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

[Perf] Use single path for all non-image snowflakes; use for..of loops over forEach; store Math.PI * 2 as a constant #71

Merged

Conversation

Tetramputechture
Copy link
Contributor

This branch introduces one major and two minor performance improvements:

  1. Use one Path for each call render() call, instead of creating new Paths for each circular snowflake. This necessitated a slight refactor, which separates the image-based and path-based drawing routines into separate methods. The check for snowflake image presence is now only done once per render call, instead of once per snowflake. This should provide the most significant improvement on lower-end hardware and in cases with a large number of snowflakes.
  2. Use for..of loops instead of forEach when updating snowflakes position and rendering them. I referred to the benchmark here.
  3. Store Math.PI * 2 as a constant only calculated once per build. This avoids rerunning this multiplication every time we render a snowflake.

I'm working on supplying quantitative benchmark results, but I'm not sure of a good way to present that; if anyone has any ideas I'd love to hear them out to help get this merged!

@cahilfoley cahilfoley force-pushed the perf/use-for-loops-over-for-each branch from 12467bf to 8ec8655 Compare September 6, 2024 10:22
@cahilfoley cahilfoley self-requested a review September 6, 2024 10:22
@cahilfoley cahilfoley merged commit 81dfeb3 into cahilfoley:main Sep 6, 2024
1 of 4 checks passed
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.

2 participants