Skip to content

Conversation

@deanlee
Copy link
Contributor

@deanlee deanlee commented Nov 6, 2025

Optimized _map_line_to_polygon with pairwise projection, minimized reshaping, and generating the triangle strip directly without intermediate Python loops.

before (run selfdrive/ui/tests/profile_onroad.py ):

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
     3606   34.184    0.009   34.184    0.009 {built-in method raylib._raylib_cffi.EndDrawing}
    10192    2.191    0.000    3.419    0.000 openpilot/selfdrive/ui/onroad/model_renderer.py:337(_map_line_to_polygon)
   306052    1.841    0.000   41.869    0.000 openpilot/.venv/lib/python3.11/site-packages/pyray/__init__.py:47(wrapped_func)
     2396    1.737    0.001    1.737    0.001 {built-in method raylib._raylib_cffi.UpdateTexture}
   116750    1.467    0.000    2.146    0.000 openpilot/.venv/lib/python3.11/site-packages/pyray/__init__.py:117(func)
    71401    1.030    0.000    1.030    0.000 {built-in method numpy.array}
    25137    0.965    0.000    1.754    0.000 openpilot/system/ui/lib/shader_polygon.py:199(triangulate)
    28730    0.757    0.000    0.757    0.000 {built-in method raylib._raylib_cffi.EndShaderMode}

after:

 ncalls  tottime  percall  cumtime  percall filename:lineno(function)
   3606   35.384    0.010   35.384    0.010 {built-in method raylib._raylib_cffi.EndDrawing}
  10192    1.987    0.000    2.768    0.000 openpilot/selfdrive/ui/onroad/model_renderer.py:335(_map_line_to_polygon)
 306052    1.925    0.000   43.395    0.000 openpilot/.venv/lib/python3.11/site-packages/pyray/__init__.py:47(wrapped_func)
   2396    1.844    0.001    1.844    0.001 {built-in method raylib._raylib_cffi.UpdateTexture}
 116750    1.543    0.000    2.256    0.000 openpilot/.venv/lib/python3.11/site-packages/pyray/__init__.py:117(func)
  28730    0.782    0.000    0.782    0.000 {built-in method raylib._raylib_cffi.EndShaderMode}

Profiler comparison (before → after):

Function Time (s) Before Time (s) After Improvement
_map_line_to_polygon 3.419 2.768 ~19% faster
shader_polygon.triangulate 1.754 eliminated

This refactor keeps rendering output identical while reducing CPU overhead and simplifying the data flow between model rendering and shader polygon generation.

@github-actions github-actions bot added the ui label Nov 6, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Nov 6, 2025

raylib UI Preview

All Screenshots

@adeebshihadeh
Copy link
Contributor

adeebshihadeh commented Nov 6, 2025

FYI @deanlee, part of the motivation for moving to the new graphics stack is the dream of kicking the UI entirely off the GPU.

This will need lots of optimization work if you want to help with that :)

We should be able to move GPU things off in small PRs one by one.

@deanlee
Copy link
Contributor Author

deanlee commented Nov 6, 2025

Not sure rlsw aligns with that direction: https://github.com/raysan5/raylib/blob/master/src/external/rlsw.h

UI perf still needs some cleanup first.

@adeebshihadeh
Copy link
Contributor

Oh we might not want to use that at all. The important thing was ditching Qt and Weston.

@deanlee deanlee marked this pull request as ready for review November 7, 2025 15:29
@deanlee deanlee force-pushed the ui-improve-mapline-new branch 4 times, most recently from 925a0d0 to e511863 Compare November 11, 2025 13:58
@deanlee deanlee force-pushed the ui-improve-mapline-new branch from e511863 to 9ffc0ba Compare November 11, 2025 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants