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

Fix: up to 80% speed and memory optimizations for slices #215

Merged
merged 2 commits into from
Sep 15, 2022

Conversation

w1kend
Copy link
Contributor

@w1kend w1kend commented Sep 13, 2022

Hello! 👋
I've made some optimizations for slices. There are also benchmarks to check the results.

And my results under:

go version go1.19 darwin/arm64
macbook air m1
goos: darwin
goarch: arm64

Flatten

name                    old time/op    new time/op    delta
Flatten/ints_10-8          294ns ± 1%     116ns ± 2%  -60.65%  (p=0.000 n=9+10)
Flatten/ints_100-8        23.7µs ± 0%     5.8µs ± 0%  -75.58%  (p=0.000 n=10+8)
Flatten/ints_1000-8       2.47ms ± 2%    0.63ms ± 1%  -74.58%  (p=0.000 n=10+8)
Flatten/strings_10-8       705ns ± 1%     227ns ± 0%  -67.83%  (p=0.000 n=10+9)
Flatten/strings_100-8     77.5µs ±15%    25.2µs ± 5%  -67.42%  (p=0.000 n=10+10)
Flatten/strings_1000-8    24.2ms ± 1%     5.5ms ± 2%  -77.46%  (p=0.000 n=10+10)

name                    old alloc/op   new alloc/op   delta
Flatten/ints_10-8         2.48kB ± 0%    0.90kB ± 0%  -63.87%  (p=0.000 n=10+10)
Flatten/ints_100-8         356kB ± 0%      82kB ± 0%  -77.00%  (p=0.000 n=10+10)
Flatten/ints_1000-8       44.9MB ± 0%     8.0MB ± 0%  -82.17%  (p=0.000 n=10+8)
Flatten/strings_10-8      5.09kB ± 0%    1.79kB ± 0%  -64.78%  (p=0.000 n=10+10)
Flatten/strings_100-8      683kB ± 0%     164kB ± 0%  -76.01%  (p=0.000 n=10+10)
Flatten/strings_1000-8    81.6MB ± 0%    16.0MB ± 0%  -80.39%  (p=0.000 n=9+10)

Chunk

name                  old time/op    new time/op    delta
Chunk/strings_10-8       120ns ± 0%      29ns ± 1%  -75.75%  (p=0.000 n=8+10)
Chunk/strings_100-8      880ns ± 0%     100ns ± 2%  -88.67%  (p=0.000 n=8+10)
Chunk/strings_1000-8    8.27µs ± 0%    0.68µs ± 1%  -91.81%  (p=0.000 n=9+9)
Chunk/ints10-8          88.5ns ± 0%    29.1ns ± 0%  -67.09%  (p=0.000 n=9+8)
Chunk/ints100-8          546ns ± 0%      99ns ± 0%  -81.96%  (p=0.000 n=8+9)
Chunk/ints1000-8        4.97µs ± 0%    0.67µs ± 1%  -86.43%  (p=0.000 n=10+10)

Replace

name                      old time/op    new time/op    delta
Replace/strings_1000-8      5.24µs ± 0%    1.29µs ± 0%  -75.46%  (p=0.008 n=5+5)
Replace/strings_10000-8     53.2µs ± 1%    13.1µs ± 1%  -75.37%  (p=0.008 n=5+5)
Replace/strings_100000-8     822µs ± 1%     127µs ± 2%  -84.50%  (p=0.016 n=5+4)
Replace/ints1000-8          1.50µs ± 0%    0.72µs ± 1%  -52.24%  (p=0.008 n=5+5)
Replace/ints10000-8         12.6µs ± 0%     3.8µs ± 5%  -69.93%  (p=0.016 n=4+5)
Replace/ints100000-8         126µs ± 1%      30µs ± 1%  -76.44%  (p=0.008 n=5+5)

Drop funcs - 10-30%

@samber samber merged commit bfae21c into samber:master Sep 15, 2022
@samber
Copy link
Owner

samber commented Sep 15, 2022

Oops, thanks for these obvious optimization!

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