Comments (6)
First of all I will just note that for mmap
of file we already end up using the mmapAlloc
JS function which calls zeroMemory
which in turn calls HEAP8.fill
, so I guess we are only talking about MAP_ANONYMOUS
mappings here?
Its true that bulkmemory should be enabled by default soon, but you can also enable it today. Is it possible to enable it for all your users, or do you not have control over the flags they use?
Having said that I don't see why we wouldn't have a emscripten_memset_js
just like we have a emscripten_memcpy_js
. Would you be able to send a PR at add that?
Finally, if you are setting as lot calls to mmap(MAP_ANONYMOUS)
, it might be worth replacing them with a simple malloc
instead since in emscripten MAP_ANONYMOUS
is simply fake, and is strictly worse that just calling malloc
+ memset
. Does you codebase have a fallback for when MAP_ANONYMOUS
is not available?
from emscripten.
First of all I will just note that for
mmap
of file we already end up using themmapAlloc
JS function which callszeroMemory
which in turn callsHEAP8.fill
, so I guess we are only talking aboutMAP_ANONYMOUS
mappings here?
Sounds like it's just MAP_ANONYMOUS, yeah.
Its true that bulkmemory should be enabled by default soon, but you can also enable it today. Is it possible to enable it for all your users, or do you not have control over the flags they use?
I am hoping we'll be able to turn it on for everyone, but we've had issues turning on uncontroversial (to me) flags so far, so I don't know when we can make it the default. We still support disabling both WASM SIMD and WASM EH for users who have old Android or iOS devices, so bulk memory potentially adds a third configuration flag once we turn it on by default. When a developer flips one or both of those off, we re-link our whole runtime using emscripten on the developer's machine to apply the appropriate flags and link in the appropriate bits.
Having said that I don't see why we wouldn't have a
emscripten_memset_js
just like we have aemscripten_memcpy_js
. Would you be able to send a PR at add that?
Yeah, I can put a PR together if it's wanted. I'll try to remember to get to that this week.
Finally, if you are setting as lot calls to
mmap(MAP_ANONYMOUS)
, it might be worth replacing them with a simplemalloc
instead since in emscriptenMAP_ANONYMOUS
is simply fake, and is strictly worse that just callingmalloc
+memset
. Does you codebase have a fallback for whenMAP_ANONYMOUS
is not available?
Thanks for the suggestion, it hadn't occurred to me that malloc could be meaningfully better here. Thankfully we don't have bare mmap calls in our codebase - they're wrapped, and the wrapper is wasm-specific - so it's possible I can turn all our mmap/munmap calls into malloc and free. I expect it will pay off, since my profiles don't show memset as a hotspot under malloc calls (malloc itself is something of a hotspot, but not as bad as memset.)
from emscripten.
Thanks for the suggestion, it hadn't occurred to me that malloc could be meaningfully better here. Thankfully we don't have bare mmap calls in our codebase - they're wrapped, and the wrapper is wasm-specific - so it's possible I can turn all our mmap/munmap calls into malloc and free. I expect it will pay off, since my profiles don't show memset as a hotspot under malloc calls (malloc itself is something of a hotspot, but not as bad as memset.)
So in your case the caller of mmap
was not relying on the resulting pages actually being zero, and when you replace with malloc
you don't need to also add memset
?
from emscripten.
Thanks for the suggestion, it hadn't occurred to me that malloc could be meaningfully better here. Thankfully we don't have bare mmap calls in our codebase - they're wrapped, and the wrapper is wasm-specific - so it's possible I can turn all our mmap/munmap calls into malloc and free. I expect it will pay off, since my profiles don't show memset as a hotspot under malloc calls (malloc itself is something of a hotspot, but not as bad as memset.)
So in your case the caller of
mmap
was not relying on the resulting pages actually being zero, and when you replace withmalloc
you don't need to also addmemset
?
In these cases, the caller is relying on them being zero, but they're new "pages" that were allocated by sbrk/pre-allocated with initial heap size, and are already zero.
from emscripten.
Thanks for the suggestion, it hadn't occurred to me that malloc could be meaningfully better here. Thankfully we don't have bare mmap calls in our codebase - they're wrapped, and the wrapper is wasm-specific - so it's possible I can turn all our mmap/munmap calls into malloc and free. I expect it will pay off, since my profiles don't show memset as a hotspot under malloc calls (malloc itself is something of a hotspot, but not as bad as memset.)
So in your case the caller of
mmap
was not relying on the resulting pages actually being zero, and when you replace withmalloc
you don't need to also addmemset
?In these cases, the caller is relying on them being zero, but they're new "pages" that were allocated by sbrk/pre-allocated with initial heap size, and are already zero.
In that case it sounds pretty risky to skip the memset after the malloc, since malloc makes no guarantees.
I wonder if we could improve our fake mmap(MAP_ANONYMOUS)
such that it could know through some internal mechanism that it can sometimes skip the memset
? Maybe unnecessary once we have emscripten_memset_js
.
from emscripten.
BTW I am adding an underscore prefix to the internal memset/memcpy helpers: #21622
from emscripten.
Related Issues (20)
- Any example to compile a project via emscripten and use it in wasmtime? HOT 10
- In `-sMODULARIZE` mode the `moduleArg` should not be modified in place
- Bind error of getting a pointer property in class
- Make mimalloc headers accessible HOT 2
- lto2.test_embind_i64_val is failing
- evaluation of std::sin in C++ is slower than in JS directly HOT 3
- [CXX1429] error when building with cmake using HOT 1
- Bug: when compiling executable, emcc "forgets" provided needed library HOT 8
- [WASMFS] FileSystemHandle.move causes OPFS to fail in Chrome HOT 1
- NODEFS not compatible with Deno when used through Pyodide HOT 4
- Unification for async APIs for the header file emscripten.h
- Unification for async APIs for the header file HTML5.h
- Unification for async APIs for the header file proxying.h
- Unification for async APIs for the header file Val.h
- Unification for async APIs for the header file Fetch.h
- Unification for async APIs for the header file webaudio.h
- 256-bit AVX intrinsics support HOT 1
- 'emcc' is not recognized as an internal or external command, operable program or batch file. HOT 2
- Multiple main function definitions can cause runtime error in chrome and crash renderer process in electron HOT 8
- Cannot convert 1698917542 to a BigInt HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from emscripten.