Skip to content

Optimizing Vector3 for everyone #4

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

Closed
NicEastvillage opened this issue Jan 31, 2025 · 5 comments
Closed

Optimizing Vector3 for everyone #4

NicEastvillage opened this issue Jan 31, 2025 · 5 comments

Comments

@NicEastvillage
Copy link
Contributor

In RLBot/python-interface#12 we briefly mentioned optimizations of Vector3.

Would it be possible to add __slots__ to the generated Vector3?

Other tricks may also be possible.

@VirxEC
Copy link
Collaborator

VirxEC commented Jan 31, 2025

I'm not sure if that will help, but it's worth a shot!

@VirxEC
Copy link
Collaborator

VirxEC commented Feb 2, 2025

This has been added in v0.13.1 - but also, I more meant to use something like numpy for vector ops

@VirxEC
Copy link
Collaborator

VirxEC commented Feb 3, 2025

Complete with https://github.com/VirxEC/rlbot_flatbuffers_py/releases/tag/v0.13.2

I've pulled out all the stops with this latest release. I've done a 180 from optimizing for pack/unpack speed to optimizing for runtime performance. I measured a 21% improvement between v0.13.1 and 0.13.2.

Because of that, unpack speed has suffered due to the shear number of objects it needs to create, especially for the ball prediction (it now takes ~250 microseconds). Experiments will have to be done, and will require more work and likely some additional (non-breaking) changes to the Python interface.

@VirxEC VirxEC closed this as completed Feb 3, 2025
@NicEastvillage
Copy link
Contributor Author

On what did you measure the 21% improvement?

@VirxEC
Copy link
Collaborator

VirxEC commented Feb 4, 2025

The time to run this code:

def find_slice_at_time(ball_prediction: flat.BallPrediction, game_time: float):
    """
    This will find the future position of the ball at the specified time. The returned
    Slice object will also include the ball's velocity, etc.
    """
    start_time = ball_prediction.slices[0].game_seconds
    approx_index = int(
        (game_time - start_time) * 120
    )  # We know that there are 120 slices per second.
    if 0 <= approx_index < len(ball_prediction.slices):
        return ball_prediction.slices[approx_index]
    return None

li = []
for t in range(1, 301):
    ball_in_future = find_slice_at_time(ballPred, t / 60)
    li.append(ball_in_future)

Went from ~70 micros to ~55micros. This average was taken after running the loop 50,000 times and I measured the same result multiple times.

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

No branches or pull requests

2 participants