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

Typed array performance #275

Open
webfiltered opened this issue Nov 4, 2024 · 0 comments
Open

Typed array performance #275

webfiltered opened this issue Nov 4, 2024 · 0 comments

Comments

@webfiltered
Copy link
Collaborator

webfiltered commented Nov 4, 2024

Litegraph makes some good use of typed arrays, however there are growing drawbacks and limitations.

  1. Typescript does not fully support typed arrays
    • Despite being fixed-length by design, it cannot be used in type inference
    • Tuples become painful to manage
    • Narrowing types sometimes requires runtime checks, potentially causing performance loss rather than gain
  2. Many third party libraries do not support them
    • Adds complexity to consumer code
    • Limits flexibility

This is resulting in needless abstractions and extraneous type-checking.

Suggestion is to convert internal use of Float32Array to number[], where appropriate. e.g. pos, size, and other places. In the render pass, arrays are used as fast memory buffers, and this usage is probably fine as is (or converted to Float64Array).

Impact / checks:

  • Precision (number not being 32bit)
  • Refactoring
  • Downstream consumers relying on Float32Array (it is far more common for consumers to replace the initial Float32Array properties with number[])
  • Over/underflow behaviour
  • Performance (likely negligible on modern engines and hardware - should be proactively tested in this case)
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

No branches or pull requests

1 participant