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

Speedup #81

Merged
merged 17 commits into from
Jun 19, 2023
Merged

Speedup #81

merged 17 commits into from
Jun 19, 2023

Conversation

ekiefl
Copy link
Owner

@ekiefl ekiefl commented Jun 19, 2023

This PR is concerned with speed.

Since the large refactor that transformed System, Cue, Table, and Ball and their delegate objects into dataclasses, pooltool has been kind of slow. After profiling the code with pprofile, I was able to make some changes all in the name of speed.

I tested tracked the speed progress on two test cases: (1) a simple shot involving 3 balls, a pocket, and a couple of cushions and (2) a 9-ball break.

Here is how the following commits speed up the simple shot:

image

And here is how they sped up the 9-ball break:

image

Another important speed is how fast the ball animations are built. This is substantial, especially when the shot is played in half speed / quarter speed (which doubles / quadruples the time taken). I wrote sandbox/continuize_and_render_timer.py so that this can be compared to the time to simulate and continuize shots.

Using that script, the current state of affairs is:

✓ Trajectories simulated in: 0:00:00.143015
✓ Trajectories continuized in: 0:00:00.040777
✓ Animation sequence rendered in: 0:00:00.027906

And the break shot:

✓ Trajectories simulated in: 0:00:00.363477
✓ Trajectories continuized in: 0:00:00.151531
✓ Animation sequence rendered in: 0:00:00.138668

If I were to increase the speed further, I would avoid storing Ball.history_cts as a BallHistory object. Instead, I would create a VectorizedBallHistory object that simply stores the arrays rvws, ss, and ts. I think this would make continuize and ball animations significantly faster by avoiding interconversion from arrays to BallHistory sequences.

ekiefl added 17 commits June 14, 2023 19:04
- Run python sandbox/break.py --time-it --load sandbox/timing.msgpack
  --no-viz
- These are called like 13k times during a break shot, and a noticeable
  amount of time is saved by caching them
- This is 10X faster, although I dont't think it's very significant in
  the grand scheme of things
- Pretty significant speedup (0.66 -> 0.53)
- I think it's fair to say this is the responsibility of the caller to
  do
- Creating an event should be cheap, since we make candidate events all
  the time throughout the shot evolution algorithm
- This was 3% of continuize
@ekiefl ekiefl merged commit 18cd352 into main Jun 19, 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.

None yet

1 participant