You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ModuleSourceProvider has ability to return NOT_MODIFIED if source was not modified to prevent compiling code 2nd time.
CachingModuleScriptProviderBase has ability to obtain cached ModuleScript if NOT_MODIFIED returned by ModuleSourceProvider. In such case the returned ModuleScript was already compiled previously.
The problem, that Require do not take into account NOT_MODIFIED, that is returned by ModuleScriptProvider when same JS code is run 2nd time:
if for the 2nd run of JS the same ModuleScriptProvider is used with same Require: moduleId was already loaded and exports where obtained previously - then it never checks if module was changed. It never do call to ModuleSourceProvider to check for NOT_MODIFIED.
If the same ModuleScriptProvider is used with another Require then executeModuleScript(...) is always called and NOT_MODIFIED is not taken into the account.
The concrete problem, that I have for now is following:
I run same JS code in Rhino in Android several times. It contains several require() and source code of these modules could be changed.
When I execute JS code 1st time then result of require() become cached in Require object in exportedModuleInterfaces field.
When I execute the same code 2nd time I want cached exports will be used if NOT_MODIFIED is returned by ModuleSourceProvider.
But if I use same Require object - it does not check for NOT_MODIFIED at all.
If I use another Require object then exports calculated for nothing : NOT_MODIFIED was returned by ModuleSourceProvider before.
Because of this either executing of exports of moment-timezone took 10 seconds every time I run JS code or changes to source of my modules are not visible in JS runtime.
The text was updated successfully, but these errors were encountered:
A single Require object will not reload modules, that is by design. Once a module is loaded in a single require instance, it's loaded, period. There's no way to reexecute it, and it would in fact not be correct to do so and come with a bunch of stability issues. (Imagine other modules depended on it, would they need to be reexecuted as well? In what order? If some code managed to hold on to old exports you'd have both old and new exports floating around, it'd be a nightmare to debug. There'd be a lot of problems with that approach.)
Using a single ModuleSourceProvider with multiple Require instances (one per global) is the right thing to do. Yes, each require will execute the script to create its exports object that belongs to that one Require (again, this is by design), but the scripts won't be recompiled each time. As long as the script isn't changed, the same compiled script will be re-executed by each Require. If executing a module takes 10 seconds, then you have one very expensive to initialize module.
Sounds like everything is working as it should, leaving this open tagged with the docs label, so the documentation can be updted with some info about this before closing this issue
Preconditions:
ModuleSourceProvider
has ability to return NOT_MODIFIED if source was not modified to prevent compiling code 2nd time.CachingModuleScriptProviderBase
has ability to obtain cached ModuleScript ifNOT_MODIFIED
returned byModuleSourceProvider
. In such case the returned ModuleScript was already compiled previously.The problem, that
Require
do not take into accountNOT_MODIFIED
, that is returned byModuleScriptProvider
when same JS code is run 2nd time:ModuleScriptProvider
is used with sameRequire
:moduleId
was already loaded andexports
where obtained previously - then it never checks if module was changed. It never do call toModuleSourceProvider
to check forNOT_MODIFIED
.ModuleScriptProvider
is used with anotherRequire
then executeModuleScript(...) is always called andNOT_MODIFIED
is not taken into the account.The concrete problem, that I have for now is following:
Rhino
inAndroid
several times. It contains severalrequire()
and source code of these modules could be changed.require()
become cached inRequire
object inexportedModuleInterfaces
field.NOT_MODIFIED
is returned by ModuleSourceProvider.But if I use same
Require
object - it does not check forNOT_MODIFIED
at all.If I use another
Require
object then exports calculated for nothing :NOT_MODIFIED
was returned byModuleSourceProvider
before.Because of this either executing of exports of
moment-timezone
took 10 seconds every time I run JS code or changes to source of my modules are not visible in JS runtime.The text was updated successfully, but these errors were encountered: