Skip to content

perf: draw vehicle parts with a single plot call - #253

Open
Goldloli wants to merge 1 commit into
ShisatoYano:mainfrom
Goldloli:perf/draw-single-plot-call
Open

Goldloli wants to merge 1 commit into
ShisatoYano:mainfrom
Goldloli:perf/draw-single-plot-call

Conversation

@Goldloli

Copy link
Copy Markdown
Contributor

Summary

Step 1 of #120: draw the vehicle with a single Axes.plot call per frame instead of one call per part.

  • Each part class (Body, Chassis, the 4 tires and the 2 axles) now exposes its pose-transformed outline through transformed_outline() instead of plotting it itself.
  • FourWheelsVehicle.draw() concatenates the 8 outlines with NaN separators (new XYArray.concatenate()) and issues one Axes.plot call for the whole vehicle, with the same line style as before.
  • The draw(axes, elems) contract of the components registered with GlobalXYVisualizer is unchanged, so Step 2 (reusing plot objects with set_data()) can be done component by component later.
  • test_rear_axle.py was updated to the new part-level API; its MockAxes is no longer needed because the part no longer plots by itself.

Part of #120 (Step 2 is left for a follow-up).

How I checked it works

  • bash run_test_suites.sh (pytest with the Agg backend): 130 passed after the change, same as before it.

  • Runtime of pure_pursuit_path_tracking in test mode (show_plot = False, 251 frames, best of repeated runs, macOS, Python 3.11, matplotlib 3.8):

    before after
    whole simulation 0.334 s 0.169 s (-49%)
    Axes.plot calls per frame 10 3
    FourWheelsVehicle.draw share of profiled runtime 74% 52%
  • Output equivalence: frames 10, 100, 200 and 250 rendered before and after are the same except 0.006-0.011% of the pixels, all on the anti-aliased edges of the vehicle lines (every differing pixel is adjacent to a line stroke; max channel delta 56).

Images

Last frame of pure_pursuit_path_tracking, before / after (the refactoring keeps the output the same):

last frame before

last frame after

Vehicle zoom at frame 100, before (left) vs after (right):

vehicle zoom before/after

Book

  • This PR doesn't change code that the book describes, or I updated those pages

Concatenate the outlines of the 8 vehicle parts with NaN separators and
draw them with one Axes.plot call per frame, instead of one call per part.

Part of ShisatoYano#120 (Step 1)

This branch has not been deployed

No deployments
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