-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Add a new compiler setting that tells the JS build output to expect that the locateFile
module hook will be used
#21927
Comments
If there are code size saving that result then we should certainly do this. Could you point the code that you think can be elided in this case? |
We already have that mechanism for arbitrary Module settings though, do we really need another named setting? |
My thought was that function locateFile(path) {
if (Module["locateFile"]) {
return Module["locateFile"](path, scriptDirectory);
}
return scriptDirectory + path;
} Could be reduced to: function locateFile(path) {
return Module["locateFile"](path, "");
} And then this code that sets up var _scriptName = typeof document != "undefined" ? document.currentScript?.src : undefined;
if (typeof __filename != "undefined") _scriptName ||= __filename;
// ...
if (ENVIRONMENT_IS_WORKER) {
scriptDirectory = self.location.href;
} else if (typeof document != "undefined" && document.currentScript) {
scriptDirectory = document.currentScript.src;
}
if (_scriptName) {
scriptDirectory = _scriptName;
}
if (scriptDirectory.startsWith("blob:")) {
scriptDirectory = "";
} else {
scriptDirectory = scriptDirectory.substr(0, scriptDirectory.replace(/[?#].*/, "").lastIndexOf("/") + 1);
} |
Do you mean We could perhaps change this meaning for certain settings such as |
BTW , if we really want to shave some serious code size we should be looking at the |
@dasa, BTW can I ask what you are using |
I have not.
Correct, for example, I have a NPM package that loads the Wasm file from a CDN. |
@sbc100 I think that is the same, unless I am missing your meaning? That is, the setting means "the user may set Module.X; if a setting is not in this list, the compiler can assume the user does not set Module.X". In fact, Line 987 in 8cc1654
So I agree with @RReverser that we may not need a new setting here, we can take advantage of the existing one, unless I'm missing something. |
I'm proposing a setting telling the compiler that it can count on the user setting |
The values in |
I guess one option would be to add new setting such Alternatively we could keep the existing setting and change its meaning for certain elements from "may have" to "will have"? |
Or perhaps as you suggest we create a specific new setting just for this? I've always disliked the setting name |
Can we imagine a use case were a developer want to be able to supply |
Idk, it seems like such a tiny saving (a few bytes of the |
It's not much, but isn't it also the code that sets |
I believe the |
Ah, so this is to save code size in the case where it is provided, sorry for misunderstanding before. I tend to agree with @RReverser that this may not be worth it. Optimizing code size for the default is worth doing - most people don't need With that said, if the code size difference was very large I'd be ok with a new setting, but in this case I think it's quite minor? I would also be ok with a generic new setting like |
This is an enhancement request.
I think this setting would reduce unnecessary JS code and complexity in the output that's left unused when
locateFile
is defined on the Module.Perhaps it could be called
USE_LOCATE_FILE
, and a runtime error would be expected iflocateFile
was not defined./cc @RReverser
The text was updated successfully, but these errors were encountered: