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

Micro optimize extend #362

Merged
merged 1 commit into from
Oct 31, 2024
Merged

Micro optimize extend #362

merged 1 commit into from
Oct 31, 2024

Conversation

arthurprs
Copy link
Contributor

@arthurprs arthurprs commented Oct 31, 2024

Improve code generation by only advancing the iterator in 2 locations (down from 4) and one less push/reserve location, which increases the chances of inlining and generates less code.

One benchmark improved (bench_extend_filtered), and the rest remains the same.

Before

test bench_extend                      ... bench:          37.69 ns/iter (+/- 0.62)
test bench_extend_filtered             ... bench:         143.90 ns/iter (+/- 10.50)
test bench_extend_filtered_small       ... bench:          19.27 ns/iter (+/- 3.83)
test bench_extend_from_slice           ... bench:          25.01 ns/iter (+/- 0.45)
test bench_extend_from_slice_small     ... bench:           6.43 ns/iter (+/- 0.02)
test bench_extend_from_slice_vec       ... bench:          65.69 ns/iter (+/- 2.89)
test bench_extend_from_slice_vec_small ... bench:          15.37 ns/iter (+/- 1.29)
test bench_extend_small                ... bench:          18.09 ns/iter (+/- 0.06)
test bench_extend_vec                  ... bench:          70.24 ns/iter (+/- 0.77)
test bench_extend_vec_filtered         ... bench:         128.12 ns/iter (+/- 11.17)
test bench_extend_vec_filtered_small   ... bench:          19.82 ns/iter (+/- 0.88)
test bench_extend_vec_small            ... bench:          14.65 ns/iter (+/- 1.08)

After

test bench_extend                      ... bench:          37.20 ns/iter (+/- 7.43)
test bench_extend_filtered             ... bench:         130.83 ns/iter (+/- 8.19)
test bench_extend_filtered_small       ... bench:          16.48 ns/iter (+/- 0.16)
test bench_extend_from_slice           ... bench:          24.96 ns/iter (+/- 0.49)
test bench_extend_from_slice_small     ... bench:           6.42 ns/iter (+/- 0.01)
test bench_extend_from_slice_vec       ... bench:          66.46 ns/iter (+/- 2.00)
test bench_extend_from_slice_vec_small ... bench:          15.94 ns/iter (+/- 0.43)
test bench_extend_small                ... bench:          16.63 ns/iter (+/- 0.03)
test bench_extend_vec                  ... bench:          70.70 ns/iter (+/- 1.83)
test bench_extend_vec_filtered         ... bench:         132.82 ns/iter (+/- 9.07)
test bench_extend_vec_filtered_small   ... bench:          20.70 ns/iter (+/- 0.77)
test bench_extend_vec_small            ... bench:          14.92 ns/iter (+/- 0.82)

Improve code generation by only advancing the iterator in 2 locations
@arthurprs arthurprs marked this pull request as ready for review October 31, 2024 09:25
Copy link
Collaborator

@mbrubeck mbrubeck left a comment

Choose a reason for hiding this comment

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

Thanks!

@mbrubeck mbrubeck added this pull request to the merge queue Oct 31, 2024
Merged via the queue into servo:v2 with commit f6ec5b2 Oct 31, 2024
6 checks passed
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.

2 participants