Skip to content

Conversation

@the-spectator
Copy link

@the-spectator the-spectator commented Nov 22, 2024

Constructing balanced_ring using Array.new(&block) saves us a range and a few array allocations.

Profiling (memory_profiler)

report = MemoryProfiler.report do
  Limiter::RateQueue.new(500, interval: 1, balanced: true)
end

report.pretty_print

Before

allocated memory by class
-----------------------------------
     25280  Array
       320  Hash
        80  Limiter::RateQueue
        72  Thread::Mutex
        40  Limiter::Clock
        40  Range

After

allocated memory by class
-----------------------------------
     24040  Array
       320  Hash
        80  Limiter::RateQueue
        72  Thread::Mutex
        40  Limiter::Clock

@the-spectator
Copy link
Author

I've signed the CLA!

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.

1 participant