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

perf: implement custom value to reduce memory allocation #32

Merged
merged 4 commits into from
Jul 2, 2024

Conversation

muktihari
Copy link
Owner

@muktihari muktihari commented Jul 2, 2024

  • When we encounter value: bool, int64, or float64; those value is no longer allocate.
  • Reduce bind memory alloc by not concating prefix and suffix on value lookup.

Expr Benchmark

goos: darwin
goarch: amd64
pkg: github.com/muktihari/expr
cpu: Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
                         old.txt                   new.txt               
                          sec/op       sec/op     vs base                
Any/KindBoolean-4       10.74µ ±  4%   10.20µ ± 1%   -5.05% (p=0.000 n=10)
Any/KindInt-4           4.997µ ±  0%   4.712µ ± 0%   -5.69% (p=0.000 n=10)
Any/KindFloat-4         7.275µ ±  0%   6.886µ ± 0%   -5.35% (p=0.000 n=10)
Any/KindImag-4          5.430µ ± 12%   5.017µ ± 0%   -7.62% (p=0.000 n=10)
Boolean/KindBoolean-4   13.12µ ± 25%   10.19µ ± 1%  -22.30% (p=0.000 n=10)
Complex128/KindImag-4   5.052µ ± 18%   4.966µ ± 1%   -1.70% (p=0.002 n=10)
Float64/KindFloat-4     7.331µ ±  3%   6.772µ ± 0%   -7.63% (p=0.000 n=10)
Int64/KindInt-4         8.484µ ± 44%   4.677µ ± 0%  -44.87% (p=0.000 n=10)
geomean                 7.373µ         6.355µ       -13.81%

                         old.txt                   new.txt               
                           B/op          B/op      vs base               
Any/KindBoolean-4       2.703Ki ± 0%   2.578Ki ± 0%  -4.62% (p=0.000 n=10)
Any/KindInt-4           1.531Ki ± 0%   1.391Ki ± 0%  -9.18% (p=0.000 n=10)
Any/KindFloat-4         2.016Ki ± 0%   1.836Ki ± 0%  -8.91% (p=0.000 n=10)
Any/KindImag-4          1.602Ki ± 0%   1.531Ki ± 0%  -4.39% (p=0.000 n=10)
Boolean/KindBoolean-4   2.672Ki ± 0%   2.578Ki ± 0%  -3.51% (p=0.000 n=10)
Complex128/KindImag-4   1.586Ki ± 0%   1.516Ki ± 0%  -4.43% (p=0.000 n=10)
Float64/KindFloat-4     1.992Ki ± 0%   1.828Ki ± 0%  -8.24% (p=0.000 n=10)
Int64/KindInt-4         1.469Ki ± 0%   1.391Ki ± 0%  -5.32% (p=0.000 n=10)
geomean                 1.894Ki        1.779Ki       -6.10%

                        old.txt                 new.txt               
                       allocs/op   allocs/op   vs base                
Any/KindBoolean-4       72.00 ± 0%   62.00 ± 0%  -13.89% (p=0.000 n=10)
Any/KindInt-4           44.00 ± 0%   32.00 ± 0%  -27.27% (p=0.000 n=10)
Any/KindFloat-4         61.00 ± 0%   44.00 ± 0%  -27.87% (p=0.000 n=10)
Any/KindImag-4          48.00 ± 0%   45.00 ± 0%   -6.25% (p=0.000 n=10)
Boolean/KindBoolean-4   70.00 ± 0%   62.00 ± 0%  -11.43% (p=0.000 n=10)
Complex128/KindImag-4   47.00 ± 0%   44.00 ± 0%   -6.38% (p=0.000 n=10)
Float64/KindFloat-4     59.00 ± 0%   43.00 ± 0%  -27.12% (p=0.000 n=10)
Int64/KindInt-4         36.00 ± 0%   32.00 ± 0%  -11.11% (p=0.000 n=10)
geomean                 53.27        44.27       -16.90%

Bind Benchmark

goos: darwin
goarch: amd64
pkg: github.com/muktihari/expr/bind
cpu: Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
                                                                        old.txt                   new.txt                
                                                                        sec/op         sec/op     vs base                
Bind/extra_small_len(s):76,_len(varInStrCount):_4,_vars:4/Bind-4       1.790µ ± 47%   1.524µ ± 20%  -14.83% (p=0.003 n=10)
Bind/small_len(s):643,_len(varInStrCount):_43,_vars:12/Bind-4          11.04µ ±  9%   10.72µ ± 31%        ~ (p=0.684 n=10)
Bind/medium_len(s):6133,_len(varInStrCount):_403,_vars:102/Bind-4      100.2µ ±  2%   104.2µ ± 29%        ~ (p=0.280 n=10)
Bind/large_len(s):61933,_len(varInStrCount):_4003,_vars:1002/Bind-4   1052.6µ ± 42%   990.8µ ±  6%   -5.88% (p=0.035 n=10)
geomean                                                                38.00µ         36.04µ         -5.16%

                                                                       old.txt                   new.txt                
                                                                         B/op          B/op      vs base                
Bind/extra_small_len(s):76,_len(varInStrCount):_4,_vars:4/Bind-4        240.0 ± 0%     184.0 ± 0%  -23.33% (p=0.000 n=10)
Bind/small_len(s):643,_len(varInStrCount):_43,_vars:12/Bind-4         2.134Ki ± 0%   1.939Ki ± 0%   -9.11% (p=0.000 n=10)
Bind/medium_len(s):6133,_len(varInStrCount):_403,_vars:102/Bind-4     18.34Ki ± 0%   16.74Ki ± 0%   -8.75% (p=0.000 n=10)
Bind/large_len(s):61933,_len(varInStrCount):_4003,_vars:1002/Bind-4   277.7Ki ± 0%   262.0Ki ± 0%   -5.64% (p=0.000 n=10)
geomean                                                               7.104Ki        6.253Ki       -11.99%

                                                                       old.txt                  new.txt               
                                                                      allocs/op    allocs/op   vs base                
Bind/extra_small_len(s):76,_len(varInStrCount):_4,_vars:4/Bind-4      13.000 ± 0%    9.000 ± 0%  -30.77% (p=0.000 n=10)
Bind/small_len(s):643,_len(varInStrCount):_43,_vars:12/Bind-4          43.00 ± 0%    31.00 ± 0%  -27.91% (p=0.000 n=10)
Bind/medium_len(s):6133,_len(varInStrCount):_403,_vars:102/Bind-4      320.0 ± 0%    218.0 ± 0%  -31.87% (p=0.000 n=10)
Bind/large_len(s):61933,_len(varInStrCount):_4003,_vars:1002/Bind-4   3.027k ± 0%   2.025k ± 0%  -33.10% (p=0.000 n=10)
geomean                                                                152.5         105.3       -30.94%

@muktihari muktihari self-assigned this Jul 2, 2024
Copy link

codecov bot commented Jul 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (1197f8e) to head (9c650c9).

Additional details and impacted files
@@            Coverage Diff            @@
##            master       #32   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            9        10    +1     
  Lines          661       698   +37     
=========================================
+ Hits           661       698   +37     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@muktihari muktihari merged commit c3dc48c into master Jul 2, 2024
3 checks passed
@muktihari muktihari deleted the perf/reduce-memory-allocation branch July 2, 2024 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant