Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracking issue of known performance issues #378

Open
22 tasks
Nicceboy opened this issue Nov 25, 2024 · 0 comments
Open
22 tasks

Tracking issue of known performance issues #378

Nicceboy opened this issue Nov 25, 2024 · 0 comments
Labels
area/codec Related to a new or existing ASN.1 codec. good first issue Good for newcomers help wanted Extra attention is needed kind/enhancement New feature or request

Comments

@Nicceboy
Copy link
Contributor

Nicceboy commented Nov 25, 2024

OER codec has been optimized fairly well at this point and some optimizations have been carried to other codecs as well.

However, there is some work to do in other codecs and they can take advantage of or note the added improvements during OER optimizations. Most of the possible improvements are related to the reduction of allocations.

BER/CER/DER

  • Output construction should always happen to the same output buffer during encoding. If this is not possible (e.g. there is a separate need to encode data before calculating the length is possible, reuse a specific worker buffer)
  • Recursive encoder instances should use existing buffers
    • Maybe add encode_buf encoding function at the same time, so caller can pass existing buffer
  • rework decode_octet_string method to return always slices instead of vectors and add constraint check at the same time
  • object_identifier_as_bytes method should take buffer as parameter and encode into that. This function is also used by other codecs.
  • Adding constraint checks potentially improves performance in few situations

UPER/APER

Most of the following optimizations can be mimiced from the OER codec, with slight modifications since its completely octet-aligned.

  • Output construction should always happen to the same output buffer during encoding. If this is not possible (e.g. there is a separate need to encode data before calculating the length is possible, reuse a specific worker buffer)
    • If the above is applied, pre-allocations are not needed anymore in encoding - however there are currently some opportunities for that which might reduce the amount of re-allocations
  • Recursive encoder instances should use existing buffers. Preamble pre-reservation and relevant overwriting must be added first.
    • Maybe add encode_buf encoding function at the same time, so caller can pass existing buffer
  • There are few closure-based patterns to decode data - this makes using borrows challenging e.g. in decode_octet_string method, so it should be re-adjusted
  • It is possible to calculate the width of the preamble and store cursor to pointing into that position in the current output buffer (all the needed values are available as constant) - all the data can be then appended to the same buffer as they appear and later the reserved preamble position is rewritten (sample in OER, needs only slight modifications)
  • The above applies for extension additions as well - store the cursor at the beginning of the extension additions, calculate the width of the extension bitmap, reserve it and then encode extension additions to the output buffer as they appear, adding length at the same time (open type). Use worker buffer to prevent new allocations when calculating length. (sample in OER, needs only slight modifications)
  • In decoder side, there are some pre-allocation opportunities left that can help on avoiding re-allocations
  • Presence tracking of optional/extended fields during decoding can use field count constants to make use of static arrays instead of using heap
  • Decoding of the extension header should also use the constants with static arrays instead of heap
  • Decoding of sequence/set can use field count constants in order to remove some heap allocations
  • Decoding anything with open type should get the data as slice instead of heap allocated vector
  • decode_length method seems to be very slow - needs some research
  • nom_bitvec and BitVec are sometimes very slow - conversions between bitvec/vec and general parsing should be benchmarked if there are improvements available by using different patterns
  • There are likely some opportunities left to take better advantage of the constraints for calculating any ranges as the constraints are now almost completely constant

OER

Unsafe improvements (may or may not added?)

  • When encoding, using unsafe get_unchecked_mut in optional/extension presence tracking for setting array index, will grant around 5% performance for general logic when extensions and optional fields are present

Errors

Some errors might introduce allocation or other performance penalties if used with format!. Errors likely need some benchmarking too.

@XAMPPRocky XAMPPRocky added kind/enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers area/codec Related to a new or existing ASN.1 codec. labels Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/codec Related to a new or existing ASN.1 codec. good first issue Good for newcomers help wanted Extra attention is needed kind/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants