Skip to content

isTypedArray in fromPoints fails with Array of floats #24

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

Closed
vorg opened this issue Jul 12, 2023 · 9 comments · Fixed by #21
Closed

isTypedArray in fromPoints fails with Array of floats #24

vorg opened this issue Jul 12, 2023 · 9 comments · Fixed by #21

Comments

@vorg
Copy link
Member

vorg commented Jul 12, 2023

No description provided.

@vorg vorg changed the title isTypedArray is fromPoints fails with Array of floats isTypedArray in fromPoints fails with Array of floats Jul 12, 2023
@dmnsgn
Copy link
Member

dmnsgn commented Jul 17, 2023

The question is broader, related to pex ecosystem: should we prohibit array of float and force typed arrays (with some utils to expand typed array easily).

@vorg
Copy link
Member Author

vorg commented Jul 17, 2023

with some utils to expand typed array easily

There are solutions like this https://github.com/vorg/geom-builder but then you depend on using geom.count instead of geom.positions.length that might be greately padded with zeros due to last array expansion. I wonder if you could expand the underlaying ArrayBuffer but keep typed arrays tight as they are only views on underlying storage.

@vorg
Copy link
Member Author

vorg commented Jan 9, 2024

should we prohibit array of float

why? how do you build geometries with unknown amount of points?

@vorg
Copy link
Member Author

vorg commented Jan 31, 2024

Also there check should happen once not in a for loop

 for (let i = 0; i < points.length / (isTypedArray ? 3 : 1); i++) {
    if (isTypedArray) {
      includePoint(a, points, i * 3);
    } else {

@vorg
Copy link
Member Author

vorg commented Jan 31, 2024

And num points should be calculated once

@dmnsgn
Copy link
Member

dmnsgn commented Jan 31, 2024

The alternative check is ArrayBuffer.isView(points) (with the caveats it also pass new DataView test), as constructor string test is meh. We use that check in couple places (pex-renderer, pex-geom, most of your geom- packages...), should it be in pex-math utils?

Re "if check and precompute point length", benchmark says "it depends":

tl;dr, on v8:

  • Comparable speeds for 8 points.
  • It is slower for a Float32Array of random points below 10000 points = length 30 000 (which is often our geometry use case) and only gets faster after that amount.
image

@vorg
Copy link
Member Author

vorg commented Jan 31, 2024

Can we do tests in Safari and FF too?

@vorg
Copy link
Member Author

vorg commented Jan 31, 2024

Another argument is that points.length / (isTypedArray ? 3 : 1) doesn't pass readability test.

@dmnsgn
Copy link
Member

dmnsgn commented Jan 31, 2024

Can we do tests in Safari and FF too?

Results are similar in Safari and FF (a bit less precision in browser) but 3 times slower..
Screenshot 2024-01-31 at 13 25 50

@dmnsgn dmnsgn mentioned this issue Feb 5, 2024
Merged
21 tasks
@dmnsgn dmnsgn closed this as completed in c459e84 Feb 5, 2024
@dmnsgn dmnsgn closed this as completed in #21 Feb 5, 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 a pull request may close this issue.

2 participants