Skip to content

push! performance tweaks #37

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

Merged
merged 2 commits into from
Mar 20, 2023
Merged

push! performance tweaks #37

merged 2 commits into from
Mar 20, 2023

Conversation

jeremiahpslewis
Copy link
Member

@jeremiahpslewis jeremiahpslewis commented Mar 19, 2023

This PR should speed up pushing to typical, multileveled Trace objects and reduces allocations, but comes at the cost of simple Trace object performance. @HenriDeh What do you think?

Running the ReinforcementLearning.jl/src/ReinforcementLearningCore/test/core/core.jl first example, 10% speed bump and 15% fewer allocations (by count)

After: 10.542 μs (133 allocations: 6.38 KiB)
Before: 11.666 μs (158 allocations: 6.95 KiB)

Simple Performance Test

using ReinforcementLearningTrajectories
using ReinforcementLearningTrajectories: AbstractTrace
using BenchmarkTools

t = Traces(;
a=[1, 2],
b=Bool[0, 1]
)

@btime push!(t, (; a=3, b=true))
# After: 283.039 ns (7 allocations: 224 bytes)
# Before: 184.911 ns (7 allocations: 192 bytes)

t = CircularArraySARTTraces(;
capacity=3,
state=Float32 => (2, 3),
action=Float32 => (2,),
reward=Float32 => (),
terminal=Bool => ()
)

@btime push!(t, ((state=ones(Float32, 2, 3), action=ones(Float32, 2))))
# After: 408.960 ns (10 allocations: 528 bytes)
# Before: 1.146 μs (22 allocations: 816 bytes)

@jeremiahpslewis jeremiahpslewis changed the title Improve push! push! performance tweaks Mar 19, 2023
@codecov-commenter
Copy link

codecov-commenter commented Mar 19, 2023

Codecov Report

Merging #37 (e025c89) into main (1f2be9a) will decrease coverage by 0.09%.
The diff coverage is 77.77%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##             main      #37      +/-   ##
==========================================
- Coverage   69.34%   69.25%   -0.09%     
==========================================
  Files          13       13              
  Lines         561      566       +5     
==========================================
+ Hits          389      392       +3     
- Misses        172      174       +2     
Impacted Files Coverage Δ
src/traces.jl 83.52% <77.77%> (-0.72%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Member

@HenriDeh HenriDeh left a comment

Choose a reason for hiding this comment

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

Cool. The change does not look major with small traces but may be consequential with large arrays.

@jeremiahpslewis jeremiahpslewis merged commit c724ba0 into main Mar 20, 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