Make pollEvent not allocate unnecessarily (#178)#179
Merged
Conversation
Just to summarize the numbers below for future reference:
> let timeToPoll = 11 * 1e-6 -- from criterion
> let bytesPerPoll = 36802144/100000 -- from weigh
> let pollsPerSec = 1/timeToPoll
> let bytesPerSecond = bytesPerPoll * pollsPerSec
> pollsPerSec
90909.09090909091
> printf "%f" (pollsPerSec * bytesPerPoll)
33456494.545454547
So that's 90,909 polls and 33.5MB per second of allocations. That's
consistent with the below findings. The GC count for 100,000
polls (36.8MB) is 35 GCs, so that's roughly 1 GC per 1MB which
corresponds to GHC's default GC settings.
Before:
Case Allocated GCs
pollEvents 10 4,632 0
pollEvents 100 38,416 0
pollEvents 1000 369,112 0
pollEvents 10000 3,680,088 3
pollEvents 100000 36,802,144 35
benchmarking pollEvents/orig
time 11.43 μs (11.37 μs .. 11.49 μs)
1.000 R² (1.000 R² .. 1.000 R²)
mean 11.41 μs (11.37 μs .. 11.48 μs)
std dev 167.3 ns (122.4 ns .. 274.7 ns)
variance introduced by outliers: 11% (moderately inflated)
After
Case Allocated GCs
pollEvents 10 1,400 0
pollEvents 100 1,400 0
pollEvents 1000 1,400 0
pollEvents 10000 1,400 0
pollEvents 100000 1,400 0
benchmarking pollEvents/check
time 11.05 μs (11.00 μs .. 11.11 μs)
1.000 R² (0.999 R² .. 1.000 R²)
mean 11.04 μs (10.99 μs .. 11.13 μs)
std dev 216.5 ns (154.8 ns .. 296.8 ns)
variance introduced by outliers: 19% (moderately inflated)
Member
Author
|
Applied to my project: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Opening a PR for posterity. See #178