Skip to content

Improve typedarray's map allocations #821

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

Merged
merged 6 commits into from
Sep 10, 2019
Merged

Improve typedarray's map allocations #821

merged 6 commits into from
Sep 10, 2019

Conversation

MaxGraey
Copy link
Member

@MaxGraey MaxGraey commented Sep 6, 2019

Not sure is it necessary optimization. @dcodeIO wdyt?

@dcodeIO
Copy link
Member

dcodeIO commented Sep 6, 2019

Hmm, unlike .filter recently, the size of the array is known beforehand in .map, so the overhead here seems to be a single load of .data, right?

@MaxGraey
Copy link
Member Author

MaxGraey commented Sep 6, 2019

Yes, but instantiate<T> internally call memory.fill which could skipped in this case. But yeah this expand size of generated bytecode. That's why I use ASC_SHRINK_LEVEL

@DanielRX
Copy link

DanielRX commented Sep 6, 2019

Does AS explicitly prevent .map being able to edit the original array (3rd param to the function)? Since in JS you have access to the array, is it possible to edit it (reducing the length maybe) which would be a problem?

@MaxGraey
Copy link
Member Author

MaxGraey commented Sep 6, 2019

@DanielRX No, typed arrays hasn't "set" accessor for length so you can't change size of typed arrays after instantiation unlike Array<T>. At least legally (in safe style). And Array#map / TypedArray#map always create new array

@dcodeIO
Copy link
Member

dcodeIO commented Sep 6, 2019

Good argument with memory.fill, and I agree that we should avoid instantiate altogether therefore, independently of shrink level. Shouldn't make a significant code size difference anyway since instantiate is basically inlined.

@MaxGraey
Copy link
Member Author

MaxGraey commented Sep 6, 2019

I switched to manual allocs without instantiate. Conditional branch also produce side effect with unnecessary retain/release

@MaxGraey MaxGraey requested a review from dcodeIO September 6, 2019 17:41
@dcodeIO
Copy link
Member

dcodeIO commented Sep 10, 2019

LGTM! Do you know if there are other uses of instantiate<T> in stdlib that can be optimized this way?

@MaxGraey
Copy link
Member Author

It seems rest instantiate<T> have necessary usage

@dcodeIO dcodeIO merged commit a4dd3a9 into AssemblyScript:master Sep 10, 2019
@MaxGraey MaxGraey deleted the improve-typedarray-map branch September 10, 2019 11:28
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.

3 participants