Add runtime detection for toResizableBuffer#27096
Conversation
4a2b43f to
11fb3c6
Compare
A nice thing about emscripten/system/lib/standalone/standalone.c Lines 138 to 141 in d1fbb02 It also skips the emscripten/tools/acorn-optimizer.mjs Lines 1081 to 1084 in d1fbb02 Thinking about this more, since emscripten/tools/feature_matrix.py Lines 143 to 151 in d1fbb02 |
|
Yes, GROWABLE_ARRAYBUFFERS should certainly be auto-enabled when the feature matrix allows is. If that isn't the case today we should fix that. |
1ef543f to
70630b5
Compare
70630b5 to
7df7165
Compare
7df7165 to
2781f78
Compare
2781f78 to
e6316ef
Compare
bda5ef7 to
6b6a0c6
Compare
…allow (#27097) See #27096 (comment) Also, remove the experimental status, since this feature is now available in all browser and we hope to feature-detect it soon and start using it even without this flag. Fixes: #26099
86aa197 to
95d431f
Compare
|
I think this change should be good to go now. PTAL. |
| // and Node.js. | ||
| // and Node.js. Even when this setting is disabled, Emscripten will still use this | ||
| // feature when available, but it include the fall back code for handling | ||
| // non-growable memories. |
There was a problem hiding this comment.
Perhaps explain why? We don't do this with other features afaik?
There was a problem hiding this comment.
I think we do do feature detection in some places.
The reason we want both approaches in this case is kind of important. There are two main cases:
-
For all users or pthreads+memory growth we probably want to use
toResizableBufferwhen available in all cases. It slightly fast since we don't need to rebuild the views each time the memory grows. There is very little cost to probing for, and using the features if its found. -
For users that know that they are only targetting newer browsers they can opt in with
-sGROWABLE_ARRAYBUFFERSwhich means we don't need run the wholegrowableHeapJS optimizer path (which is the thing that slows down all the HEAP accesses in normal builder). These users see even more of a benefit, but their code won't run on older browsers.
There was a problem hiding this comment.
For example of where we do feature detection you can see many by doing git grep "if .*globalThis" src.
In most cases we don't have setting to opt out of the feature-detection and just assume the feature is present. In some cases we can use the feature matrix to detect when the feature-detection is not needed.
In the long run I think we may just want to delete this setting (or at least make it internal) since it can be driven completely by the feature matrix.
There was a problem hiding this comment.
For example of where we do feature detection you can see many by doing git grep "if .*globalThis" src.
Do we have feature flags for those things, though? E.g. one result is
src/lib/libembind.js: if (!globalThis.FinalizationRegistry) {
I don't think we have a flag for that, so we have to check it.
That is, what seems new to me is Even when this setting is disabled, Emscripten will still use this feature when available - do we do that anywhere else? Normally if a user disables a setting, we don't use the feature, afaik
There was a problem hiding this comment.
For this feature I think we want two things:
- We want to use it whenever we can. There is really no need to be able to completely opt out. (just like with
FinalizationRegistry). - We want to be able to create a built where we assume its always present (because we want to be able to opt out of the cost of using
growableHeapJS transform.
We maybe its not something we have done before (both features detection and a setting). But I certainly think its justified in this case.
Unless you have any other ideas about how to better take advantage of this by default?
There was a problem hiding this comment.
In other words, a user specifies -sGROWABLE_ARRAYBUFFERS=0 what they are saying is "support browser that don't have this feature", not "ignore this feature, even when available".
95d431f to
a65cb5c
Compare
5988ea6 to
46fcff4
Compare
46fcff4 to
18b2604
Compare
18b2604 to
916a95e
Compare
|
I've rephrased both the ChangeLog entry and the settings documentation to better describe the default behaviour and why you might still want to opt in using the explicit settings. |
331ee95 to
4aba359
Compare
Since this feature is now supported by all major browsers, we want to take advantage of it whenever possible to improve memory growth efficiency. We keep the `GROWABLE_ARRAYBUFFERS` compile-time setting to allow forcing its use and removing the fallback code, which saves some code size and avoids runtime checks. Fixes emscripten-core#27084
4aba359 to
6f35636
Compare
Since this is now shipping in the current version of all major browsers
we want to take advantage of it whenever possible.
See the ChangeLog entry and docs for why it still makes sense to keep
the explicit
GROWABLE_ARRAYBUFFERSsetting around (at least fornow).
As a side effect this change also works around #27084.