Skip to content

Conversation

@sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Jun 11, 2021

This avoids the extra export from wasm and the potential
codesize of including memset. Its probably faster and
smaller over the wire too.

Using TypedArray:fill looks fine on all the current
min browser versions we support:
https://caniuse.com/mdn-javascript_builtins_typedarray_fill

If we need to support even older browsers we can always
ifdef/polyfill at this single location in the future.

@sbc100 sbc100 changed the title Add zeroMemory JS utility function to avoid _memset. NFC Add zeroMemory JS utility function to avoid exporting _memset. NFC Jun 11, 2021
@sbc100 sbc100 requested a review from kripken June 11, 2021 23:07
},

$zeroMemory: function(address, size) {
HEAPU8.fill(0, address, address + size);
Copy link
Member

Choose a reason for hiding this comment

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

How about adding something like this:

#if LEGACY_VM_SUPPORT
  if (!HEAPU8.fill) {
    (for var i = 0; i < size; i++) {
      HEAPU8[address + i] = 0;
    }
    return;
  }
#endif

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good idea!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I do kind of worry, in general, about adding complexity like this before knowing if we really need it because it will make it really hard to ever know it is used, and its really hard to test.

Copy link
Member

Choose a reason for hiding this comment

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

We can test it, if we think it's worth it - do HEAPU8.fill = null to force the "polyfill" to be used, and build with legacy VM support. I think we have some tests like that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Do you want me to go back to add one? I'm tempted to leave it.

This avoids the extra export from wasm and the potential
codesize of including memset.  Its probably faster and
smaller over the wire too.

Using TypedArray:fill looks fine on all the current
min browser versions we support:
https://caniuse.com/mdn-javascript_builtins_typedarray_fill

If we need to support even older browsers we can always
ifdef/polyfill at this single location in the future.
@sbc100 sbc100 merged commit 315d362 into main Jun 12, 2021
@sbc100 sbc100 deleted the zeroMemory branch June 12, 2021 01:55
sbc100 added a commit that referenced this pull request Nov 30, 2021
I recently landed #15617 which inadvertently broke asan builds because,
under asan, there was a real dependency on `_memset` in the
`withBuiltinMalloc` wrapper.   However this dependency is no longer
needed since the use of `_memset` was removed from the JS library code
in #14441.
sbc100 added a commit that referenced this pull request Nov 30, 2021
I recently landed #15617 which inadvertently broke asan builds because,
under asan, there was a real dependency on `_memset` in the
`withBuiltinMalloc` wrapper.   However this dependency is no longer
needed since the use of `_memset` was removed from the JS library code
in #14441.
sbc100 added a commit that referenced this pull request Nov 30, 2021
I recently landed #15617 which inadvertently broke asan builds because,
under asan, there was a real dependency on `_memset` in the
`withBuiltinMalloc` wrapper.   However this dependency is no longer
needed since the use of `_memset` was removed from the JS library code
in #14441.
mmarczell-graphisoft pushed a commit to GRAPHISOFT/emscripten that referenced this pull request Jan 5, 2022
…5654)

I recently landed emscripten-core#15617 which inadvertently broke asan builds because,
under asan, there was a real dependency on `_memset` in the
`withBuiltinMalloc` wrapper.   However this dependency is no longer
needed since the use of `_memset` was removed from the JS library code
in emscripten-core#14441.
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