Skip to content

perf: mathematical optimization pass - eliminate redundant calculations#2

Open
crunchy4159 wants to merge 1 commit intoouch3994:mainfrom
crunchy4159:patch-1
Open

perf: mathematical optimization pass - eliminate redundant calculations#2
crunchy4159 wants to merge 1 commit intoouch3994:mainfrom
crunchy4159:patch-1

Conversation

@crunchy4159
Copy link

Mathematical Optimization Pass
Eliminated redundant calculations in the rendering pipeline. Main focus was drawsubhasesroutine() which was recalculating (Marker * opticPercent * 180 / scaling) about 200 times per frame. Added a simple pre-computation: scale_factor = opticPercent * 180 / scaling, then just multiply each marker by that. Saves roughly 600 floating-point operations per frame.

Also pulled out conversion constants that were being recalculated repeatedly:

This eliminates ~14 divisions per frame and makes the code more readable.

Other quick changes:

math.hypot(x, y) instead of manual sqrt calculation (2 places) 2 ** exp instead of pow(2, exp) (faster, optimized by interpreter) Pre-computed EMA_BETA = 0.85 constant
Expected gain: ~622 fewer floating-point ops per frame = +3 to 5 FPS (35 → 38-40 FPS)

I'm working on getting my own setup for this, but until then I need you to test these upgrades! I plan to get your suggested improvements done as well but I think a higher framerate and overall efficiency is a good place to start.

Testing: Run on your setup and verify FPS improvement. Baseline seemed to be about 35 FPS stable. Target is 38-40 FPS sustained with no visual artifacts or calculation errors. Monitor scope accuracy at various zoom levels.

Mathematical Optimization Pass
Eliminated redundant calculations in the rendering pipeline. Main focus was drawsubhasesroutine() which was recalculating (Marker * opticPercent * 180 / scaling) about 200 times per frame. Added a simple pre-computation: scale_factor = opticPercent * 180 / scaling, then just multiply each marker by that. Saves roughly 600 floating-point operations per frame.

Also pulled out conversion constants that were being recalculated repeatedly:

This eliminates ~14 divisions per frame and makes the code more readable.

Other quick changes:

math.hypot(x, y) instead of manual sqrt calculation (2 places)
2 ** exp instead of pow(2, exp) (faster, optimized by interpreter)
Pre-computed EMA_BETA = 0.85 constant
Expected gain: ~622 fewer floating-point ops per frame = +3 to 5 FPS (35 → 38-40 FPS)

I'm working on getting my own setup for this, but until then I need you to test these upgrades! I plan to get your suggested improvements done as well but I think a higher framerate and overall efficiency is a good place to start.

Testing: Run on your setup and verify FPS improvement. Baseline seemed to be about 35 FPS stable. Target is 38-40 FPS sustained with no visual artifacts or calculation errors. Monitor scope accuracy at various zoom levels.
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