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: use slab allocation for strings and bytes #255

Merged
merged 6 commits into from
May 28, 2023
Merged

Conversation

nrwiersma
Copy link
Member

This PR adds support for slab allocation for strings and bytes smaller than 1024 bytes, but will likely be all of them.
This creates a new fast path and centralises the read code, and it is now basically identical.

The benchmarked changes are as follows:

name                      old time/op    new time/op    delta
SuperheroDecode-8            281ns ± 0%     245ns ± 2%   -12.81%  (p=0.000 n=8+10)
SuperheroEncode-8            202ns ± 1%     203ns ± 3%      ~     (p=0.255 n=10+10)
PartialSuperheroDecode-8     119ns ± 1%     111ns ± 1%    -6.82%  (p=0.000 n=10+10)
SuperheroGenericDecode-8    1.44µs ± 1%    1.38µs ± 0%    -3.63%  (p=0.000 n=9+9)
SuperheroGenericEncode-8     258ns ± 1%     278ns ± 1%    +7.84%  (p=0.000 n=9+9)
SuperheroWriteFlush-8        167ns ± 1%     169ns ± 1%    +1.06%  (p=0.023 n=9+10)

name                      old alloc/op   new alloc/op   delta
SuperheroDecode-8            64.0B ± 0%     47.0B ± 0%   -26.56%  (p=0.000 n=10+10)
SuperheroEncode-8             112B ± 0%      112B ± 0%      ~     (all equal)
PartialSuperheroDecode-8     16.0B ± 0%      9.0B ± 0%   -43.75%  (p=0.000 n=10+10)
SuperheroGenericDecode-8    1.70kB ± 0%    1.68kB ± 0%    -1.00%  (p=0.000 n=10+10)
SuperheroGenericEncode-8     80.0B ± 0%     80.0B ± 0%      ~     (all equal)
SuperheroWriteFlush-8        0.00B          0.00B           ~     (all equal)

name                      old allocs/op  new allocs/op  delta
SuperheroDecode-8             4.00 ± 0%      0.00       -100.00%  (p=0.000 n=10+10)
SuperheroEncode-8             1.00 ± 0%      1.00 ± 0%      ~     (all equal)
PartialSuperheroDecode-8      1.00 ± 0%      0.00       -100.00%  (p=0.000 n=10+10)
SuperheroGenericDecode-8      33.0 ± 0%      29.0 ± 0%   -12.12%  (p=0.000 n=10+10)
SuperheroGenericEncode-8      3.00 ± 0%      3.00 ± 0%      ~     (all equal)
SuperheroWriteFlush-8         0.00           0.00           ~     (all equal)

@nrwiersma nrwiersma self-assigned this May 28, 2023
Ullaakut
Ullaakut previously approved these changes May 28, 2023
Copy link

@Ullaakut Ullaakut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM, I just find it weird to pass a string of the type for error reporting that does not seem to be specific to the returned type.

reader.go Outdated Show resolved Hide resolved
@nrwiersma
Copy link
Member Author

It allows specific errors, which are helpful. Can be renamed to op perhaps

@nrwiersma nrwiersma merged commit ccbe008 into main May 28, 2023
@nrwiersma nrwiersma deleted the slab-allocation branch May 28, 2023 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants