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

Make pollEvent not allocate unnecessarily (#178) #179

Merged
merged 1 commit into from
Apr 26, 2018

Conversation

chrisdone
Copy link
Member

@chrisdone chrisdone commented Apr 26, 2018

Opening a PR for posterity. See #178

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)
@chrisdone chrisdone requested a review from ocharles April 26, 2018 16:53
@chrisdone
Copy link
Member Author

Applied to my project:

Case                Allocated  GCs
pollEvents 10           1,800    0
pollEvents 100         15,424    0
pollEvents 1000       144,520    0
pollEvents 10000    1,439,496    1
pollEvents 100000  14,401,552   13

gcless-0.1.0.0: Test suite gcless-test passed
Completed 2 action(s).
bash-3.2$ stack test gcless
sdl2-2.4.0.1: configure (lib)
sdl2-2.4.0.1: build (lib)
sdl2-2.4.0.1: copy/register
gcless-0.1.0.0: configure (test)
Configuring gcless-0.1.0.0...
gcless-0.1.0.0: build (test)
Preprocessing test suite 'gcless-test' for gcless-0.1.0.0..
Building test suite 'gcless-test' for gcless-0.1.0.0..
[1 of 1] Compiling Main             ( Space.hs, .stack-work/dist/x86_64-osx/Cabal-2.0.1.0/build/gcless-test/gcless-test-tmp/Main.o ) [SDL.Event changed]
Linking .stack-work/dist/x86_64-osx/Cabal-2.0.1.0/build/gcless-test/gcless-test ...
gcless-0.1.0.0: test (suite: gcless-test)

Progress: 2/3
Case               Allocated  GCs
pollEvents 10          1,672    0
pollEvents 100         1,672    0
pollEvents 1000        1,672    0
pollEvents 10000       1,672    0
pollEvents 100000      1,672    0

gcless-0.1.0.0: Test suite gcless-test passed

@chrisdone chrisdone merged commit 4bde0c1 into master Apr 26, 2018
@chrisdone chrisdone deleted the poll-event-allocs branch April 26, 2018 22:42
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