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

Improve performance for const field #27

Merged
merged 1 commit into from
Oct 19, 2023

Conversation

Tortar
Copy link
Contributor

@Tortar Tortar commented Oct 18, 2023

This improves the performance for const fields while having the performance for mutable fields nearly equal to before.

Incredibly enough this beats base mutable structs by a huge amount!!

julia> using ProtoStructs

julia> @proto mutable struct A
           const x::Int
           const y::Int
       end

julia> mutable struct B
           const x::Int
           const y::Int
       end

julia> v_a = [A(x, x) for x in 1:1000];

julia> v_b = [B(x, x) for x in 1:1000];

julia> using BenchmarkTools

julia> @benchmark sum(x.y for x in $v_a)
BenchmarkTools.Trial: 10000 samples with 700 evaluations.
 Range (min  max):  177.974 ns  397.629 ns  ┊ GC (min  max): 0.00%  0.00%
 Time  (median):     183.216 ns               ┊ GC (median):    0.00%
 Time  (mean ± σ):   186.304 ns ±  11.263 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

    ▃▆██▇▆▄▂▁ ▁▃▃▃▂▂▂▁▁                                         ▂
  ▂█████████████████████████▇▇▆▆▅▆▆▇▆▄▄▆▆▄▅▄▆▅▅▄▅▆▅▆▆▅▆▆▇▆▇▆▅▂▅ █
  178 ns        Histogram: log(frequency) by time        233 ns <

 Memory estimate: 0 bytes, allocs estimate: 0.

julia> @benchmark sum(x.y for x in $v_b)
BenchmarkTools.Trial: 10000 samples with 57 evaluations.
 Range (min  max):  871.544 ns    4.771 μs  ┊ GC (min  max): 0.00%  0.00%
 Time  (median):     872.877 ns               ┊ GC (median):    0.00%
 Time  (mean ± σ):   889.405 ns ± 114.206 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

  █                                                             ▁
  █▄▄▃▃▁▁▄▄▃▁▄▄▆▇▇▆▅▅▆▆▆▆▇▄▅▅▅▅▅▄▅▃▅▅▅▅▅▅▄▃▄▄▄▃▄▄▁▁▅▁▃▄▄▄▃▃▄▄▃▄ █
  872 ns        Histogram: log(frequency) by time       1.44 μs <

 Memory estimate: 0 bytes, allocs estimate: 0.

Almost looks like something to say to some Julia core developers, but I assume there are probably good reasons why the perf difference is that big

@codecov
Copy link

codecov bot commented Oct 18, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (efd4ee4) 97.41% compared to head (6d7cc4c) 97.50%.
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #27      +/-   ##
==========================================
+ Coverage   97.41%   97.50%   +0.08%     
==========================================
  Files           2        2              
  Lines         116      120       +4     
==========================================
+ Hits          113      117       +4     
  Misses          3        3              
Files Coverage Δ
src/ProtoStruct.jl 97.47% <100.00%> (+0.08%) ⬆️

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

@Tortar Tortar changed the title Improve performance for const field (Beating Base!) Improve performance for const field Oct 18, 2023
@Tortar
Copy link
Contributor Author

Tortar commented Oct 18, 2023

Actually it seems like it works that well only when all fields are constants, but still maybe it is good to have also this opt

@Tortar
Copy link
Contributor Author

Tortar commented Oct 18, 2023

Actually (2) with more real benchmarks I see almost no improvement, and also I still see the proto mutable version lagging behind the normal version by a lot (10x)

@BeastyBlacksmith BeastyBlacksmith merged commit 90d0c63 into BeastyBlacksmith:master Oct 19, 2023
13 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