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

Pass ArrayBitSet by *const instead of by value #14129

Closed
wants to merge 1 commit into from

Conversation

Jarred-Sumner
Copy link
Contributor

@Jarred-Sumner Jarred-Sumner commented Dec 30, 2022

ArrayBitSet.isSet was doing a memcpy of the entire masks array when you call a function like isSet. This is mostly noticeable in debug builds.

For larger bitsets, that is very expensive in debug builds

image

image

For a release build of bun, it's a very slight performance improvement (note how the max is lower)

hyperfine "bun-before bun index.js" "bun bun index.js" --warmup=2
Benchmark 1: bun-before bun index.js
  Time (mean ± σ):      1.701 s ±  0.008 s    [User: 3.227 s, System: 0.135 s]
  Range (minmax):    1.686 s1.713 s    10 runs

Benchmark 2: bun bun index.js
  Time (mean ± σ):      1.680 s ±  0.005 s    [User: 3.188 s, System: 0.136 s]
  Range (minmax):    1.673 s1.689 s    10 runs

Summary
  'bun bun index.js' ran
    1.01 ± 0.01 times faster than 'bun-before bun index.js'

@andrewrk
Copy link
Member

Thanks. Please give me some time to investigate fixing this in the compiler rather than in the standard library. Since the compiler is allowed to pass this data by reference, it should have made this choice here.

@Jarred-Sumner
Copy link
Contributor Author

Sounds good. It would be better if the compiler just did this

@wooster0
Copy link

Here's a similar case btw: #13518 maybe this change can also be reverted and instead be fixed in the compiler.

`ArrayBitSet.isSet` was doing a memcpy of the entire `masks` array
andrewrk added a commit that referenced this pull request May 31, 2023
The Zig language allows the compiler to make this optimization
automatically. We should definitely make the compiler do that, and
revert this commit. However, that will not happen in this branch, and I
want to continue to explore achieving performance parity with
merge-base. So, this commit changes all InternPool parameters to be
passed by const pointer rather than by value.

I measured a 1.03x ± 0.03 speedup vs the previous commit compiling the
(set of passing) behavior tests. Against merge-base, this commit is
1.17x ± 0.04 slower, which is an improvement from the previous
measurement of 1.22x ± 0.02.

Related issue: #13510
Related issue: #14129
Related issue: #15688
andrewrk added a commit that referenced this pull request Jun 4, 2023
The Zig language allows the compiler to make this optimization
automatically. We should definitely make the compiler do that, and
revert this commit. However, that will not happen in this branch, and I
want to continue to explore achieving performance parity with
merge-base. So, this commit changes all InternPool parameters to be
passed by const pointer rather than by value.

I measured a 1.03x ± 0.03 speedup vs the previous commit compiling the
(set of passing) behavior tests. Against merge-base, this commit is
1.17x ± 0.04 slower, which is an improvement from the previous
measurement of 1.22x ± 0.02.

Related issue: #13510
Related issue: #14129
Related issue: #15688
jacobly0 pushed a commit to jacobly0/zig that referenced this pull request Jun 11, 2023
The Zig language allows the compiler to make this optimization
automatically. We should definitely make the compiler do that, and
revert this commit. However, that will not happen in this branch, and I
want to continue to explore achieving performance parity with
merge-base. So, this commit changes all InternPool parameters to be
passed by const pointer rather than by value.

I measured a 1.03x ± 0.03 speedup vs the previous commit compiling the
(set of passing) behavior tests. Against merge-base, this commit is
1.17x ± 0.04 slower, which is an improvement from the previous
measurement of 1.22x ± 0.02.

Related issue: ziglang#13510
Related issue: ziglang#14129
Related issue: ziglang#15688
andrewrk added a commit that referenced this pull request Jun 11, 2023
The Zig language allows the compiler to make this optimization
automatically. We should definitely make the compiler do that, and
revert this commit. However, that will not happen in this branch, and I
want to continue to explore achieving performance parity with
merge-base. So, this commit changes all InternPool parameters to be
passed by const pointer rather than by value.

I measured a 1.03x ± 0.03 speedup vs the previous commit compiling the
(set of passing) behavior tests. Against merge-base, this commit is
1.17x ± 0.04 slower, which is an improvement from the previous
measurement of 1.22x ± 0.02.

Related issue: #13510
Related issue: #14129
Related issue: #15688
@andrewrk
Copy link
Member

I created a reduction of this issue: #17580

I made it a high priority issue but denying any more requests to do the workaround in the standard library.

@andrewrk andrewrk closed this Oct 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants