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

feat: compute buffer size ahead of time #23

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Commits on Mar 31, 2022

  1. feat: compute buffer size ahead of time

    The current implementation loops over message fields and each field
    encoder creates a `Uint8Array` which is added to a `Uint8ArrayList`
    and stitched together at the end of the process.
    
    Other implementations compute the expected length of the serialized
    message, allocate a buffer that size then have encoders write their
    data into it at the correct offsets.
    
    This PR makes protons compute the final message buffer size first in
    the same way.
    
    Thing is, it doesn't seem to make a huge amount of difference to performance.
    
    Before:
    
    ```
    Running "Encode/Decode" suite...
    Progress: 100%
    
      pbjs:
        12 166 ops/s, ±3.92%   | 5.12% slower
    
      protons:
        9 755 ops/s, ±2.19%    | slowest, 23.93% slower
    
      protobufjs:
        12 823 ops/s, ±2.02%   | fastest
    
    Finished 3 cases!
      Fastest: protobufjs
      Slowest: protons
    ```
    
    After:
    
    ```
    Running "Encode/Decode" suite...
    Progress: 100%
    
      pbjs:
        11 866 ops/s, ±3.43%   | 2.05% slower
    
      protons:
        9 356 ops/s, ±2.45%    | slowest, 22.77% slower
    
      protobufjs:
        12 114 ops/s, ±2.16%   | fastest
    
    Finished 3 cases!
      Fastest: protobufjs
      Slowest: protons
    ```
    achingbrain committed Mar 31, 2022
    Configuration menu
    Copy the full SHA
    fecfedd View commit details
    Browse the repository at this point in the history