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

GODRIVER-2914 bsoncodec/bsonrw: eliminate encoding allocations #1323

Merged
merged 5 commits into from
Sep 12, 2023

Commits on Aug 22, 2023

  1. bsoncodec/bsonrw: eliminate encoding allocations

    This commit eliminates all allocations during marshalling (except for
    the final []byte slice allocation, which is unavoidable). This matches
    the behavior of encoding/json. It also prevents the vwPool from leaking
    writers and includes a few small optimizations to the value_writer.
    
    Other Changes:
       * bsoncodec: reduce use of reflect.Value.Interface()
       * bson: use a buffer pool instead of SliceWriter to eliminate 2 allocs
       * bsonrw: use references to slice indexes
    
    This work builds off of mongodb#1313
    and uses the BenchmarkCode* suite added by that PR.
    
    The combined performance improvement is below:
    
    ```
    goos: darwin
    goarch: arm64
    pkg: go.mongodb.org/mongo-driver/bson
                          │ base.20.txt  │             new.20.txt              │
                          │    sec/op    │   sec/op     vs base                │
    CodeUnmarshal/BSON-10    3.177m ± 1%   2.202m ± 1%  -30.68% (p=0.000 n=20)
    CodeMarshal/BSON-10     2922.7µ ± 0%   757.1µ ± 2%  -74.10% (p=0.000 n=20)
    geomean                  3.047m        1.291m       -57.63%
    
                          │ base.20.txt  │               new.20.txt               │
                          │     B/s      │      B/s       vs base                 │
    CodeUnmarshal/BSON-10   582.5Mi ± 1%    840.4Mi ± 1%   +44.26% (p=0.000 n=20)
    CodeMarshal/BSON-10     633.2Mi ± 0%   2444.3Mi ± 2%  +286.03% (p=0.000 n=20)
    geomean                 607.3Mi         1.400Gi       +135.99%
    
                          │ base.20.txt  │              new.20.txt              │
                          │     B/op     │     B/op      vs base                │
    CodeUnmarshal/BSON-10   4.219Mi ± 0%   4.148Mi ± 0%   -1.69% (p=0.000 n=20)
    CodeMarshal/BSON-10     2.818Mi ± 3%   1.630Mi ± 0%  -42.16% (p=0.000 n=20)
    geomean                 3.448Mi        2.600Mi       -24.59%
    
                          │  base.20.txt   │              new.20.txt              │
                          │   allocs/op    │  allocs/op   vs base                 │
    CodeUnmarshal/BSON-10      230.4k ± 0%   220.7k ± 0%    -4.21% (p=0.000 n=20)
    CodeMarshal/BSON-10     94066.000 ± 0%    1.000 ± 0%  -100.00% (p=0.000 n=20)
    geomean                    147.2k         469.7        -99.68%
    ```
    charlievieth authored and matthewdale committed Aug 22, 2023
    Configuration menu
    Copy the full SHA
    f9c485a View commit details
    Browse the repository at this point in the history

Commits on Sep 5, 2023

  1. Code review changes.

    matthewdale committed Sep 5, 2023
    Configuration menu
    Copy the full SHA
    4beb9fe View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    80680c8 View commit details
    Browse the repository at this point in the history

Commits on Sep 6, 2023

  1. Configuration menu
    Copy the full SHA
    603bb4a View commit details
    Browse the repository at this point in the history

Commits on Sep 11, 2023

  1. Configuration menu
    Copy the full SHA
    6c41835 View commit details
    Browse the repository at this point in the history