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: router workers and optimizations #385

Merged
merged 10 commits into from
Aug 29, 2024
Merged

perf: router workers and optimizations #385

merged 10 commits into from
Aug 29, 2024

Conversation

DanielSchiavini
Copy link
Contributor

@DanielSchiavini DanielSchiavini commented Aug 21, 2024

  • Fixes Curvejs Performance: (Router swap) #312
  • Runs the router graph creation and route finding algorithms in web workers, for UI responsivity
  • This should be backwards compatible for any clients. It runs synchronously in nodejs.
  • Route graph algorithm is not changed, just moved (a few changes were done to avoid list spread syntax, tsc uses helpers for that that do not work in a web worker)
  • Route finding algorithm is optimized to preemptively stop routes when they are not possibly the best choices based on minTvl and route length.
    • Route finding is roughly 3x faster (worst case, no match) up to 300x faster (best case, direct match) - check yourself if you wish with commit 892ec4e

@DanielSchiavini
Copy link
Contributor Author

DanielSchiavini commented Aug 21, 2024

Note in the following profile how the arced part of the code is now being ran in a worker, so it doesn't block the UI thread anymore.

image

The route graph construction still happens in the UI thread for now, as we need the global curvejs state.

@DanielSchiavini DanielSchiavini changed the title Move route finding to a worker thread Router workers and performance improvements Aug 24, 2024
@DanielSchiavini DanielSchiavini marked this pull request as ready for review August 24, 2024 09:20
@DanielSchiavini
Copy link
Contributor Author

The new algorithm was first isolated in #386 so it might be easier to review there. In that PR the code was 3x faster, but commit bad8491 made the best case dramatically more efficient

@@ -4,9 +4,11 @@

/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes the worker code output a bit better - I think es6 is already well supported anyway

@DanielSchiavini
Copy link
Contributor Author

Screencast.from.26-08-24.09.33.15.webm

Signed-off-by: Daniel Schiavini <daniel.schiavini@gmail.com>
Signed-off-by: Daniel Schiavini <daniel.schiavini@gmail.com>
@DanielSchiavini DanielSchiavini changed the title Router workers and performance improvements perf: router workers and optimizations Aug 28, 2024
@Macket Macket merged commit cd36cb4 into master Aug 29, 2024
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.

Curvejs Performance: (Router swap)
2 participants