July 7, 2025

BER Encoding Options to Improve Performance

The BER encoder/decoders in the balber package provide configuration options that can be used to potentially improve the runtime performance of decoding a BER message. BER decoding performance was highlighted as a top users priority in BDE Expo 2024. However, these options come with some Warning: Using these Options Safely that users should be aware of.

The currently available options are providing a length hint for encoded arrays (newly introduced) and using a binary format for date and time types (legacy option).

When an array length hint enabled, the encoder will encode the array’s length with the array’s data, as opposed to supplying the data and a completion indicator. Having the length allows the decoder to pre-allocate memory, allowing for potential performance improvements. balber::BerEncoder has been augmented to emit array length hints when possible (not all data structures support encoding the hint due to backwards compatability issues). To enable hints, the balber::BerEncoderOptions “EncodeArrayLengthHints” attribute must be set true (using setEncodeArrayLengthHints). Note that for large arrays, decoder performance may improve by over 10%.

The binary format for date and time types encodes these types in binary as opposed to a text representation, resulting in a reduction in parsing required in the decoder. While date and time heavy messages will see a dramatic decoding improvement, in typical types decoder performance may improve by over 5%. Additional information can be found on BER Binary encoding for Date and Time types.

Warning: Using these Options Safely

It is only safe to use array length hints when communication with a balber BER decoder built using the BDE 4.26 release or later, or a decoder having the balber::BerDecoderOptions “SkipUnknownElements” attribute set to true.

balber::BerEncoderOptionsUtil

The balber::BerEncoderOptionsUtil provides a struct of utility functions for configuring balber::BerEncoderOptions object. In particular, this utility can be used to set the recommended options needed for encoding BER messages that are time-efficient to decode (enabling a binary date-time representation and using array length hints). Using this configuration may improve decoding performance by 15% or more, relative to the default configuration. This utility can also be used to set a balber::BerEncoderOptions object to its default state.

balber::BerEncoderOptions options;

balber::BerEncoderOptionsUtil::setMode(
                            &options,
                            balber::BerEncoderOptionsUtil::e_FAST_20250615);