Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Optimization] use memoized hashes in Results to get better lookup times #500

Merged
merged 1 commit into from
Jan 24, 2024

Conversation

Drowze
Copy link
Contributor

@Drowze Drowze commented Jan 23, 2024

Running Coverband with a significantly big project (I'm currently working on one wtih ~4600 files) may get quite slow. While profiling the project, I found that one big culprit is the Results class, where there's a lot of O(n) lookup operations that could but are not currently being memoized.

This PR adds such optimization: replacing find operations for hash lookups (so only the first lookup of eager and runtime type results is slow - due to building the lookup hash)

This optimization alone brought the following load improvement to the coverage report page:

# NOTE: running on a HashRedisStore with ~4600 files
# command used:
Benchmark.measure do
  Coverband::Reporters::Web.new.tap do |cov|
    cov.instance_variable_set(:@request,Rack::Request.new(Rack::MockRequest.env_for("/")))
  end.index
  nil
end

# before
# => #<Benchmark::Tms:0x00007f74bf2ee240 @cstime=0.0, @cutime=0.0, @label="", @real=33.93276486300056, @stime=3.5702559999999997, @total=34.058608, @utime=30.488352>

# after
# => #<Benchmark::Tms:0x00007efe452aa248 @cstime=0.0, @cutime=0.0, @label="", @real=25.779949678000776, @stime=3.301538, @total=25.864683, @utime=22.563145>

Also tested with both this and #499

# with both this and #499
# => #<Benchmark::Tms:0x00007f1374de55b0 @cstime=0.0, @cutime=0.0, @label="", @real=8.71669229300096, @stime=0.7920630000000002, @total=8.723904, @utime=7.931840999999999>

@danmayer danmayer self-assigned this Jan 24, 2024
@danmayer
Copy link
Owner

Nice, this is a great improvement and clean

@danmayer danmayer merged commit 42718a4 into danmayer:main Jan 24, 2024
64 checks passed
@danmayer
Copy link
Owner

changes are in the 6.0.2 release, thanks so much for your contributions

@Drowze Drowze deleted the optimize-results branch January 24, 2024 13:02
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants