endojs / endo

Endo is a distributed secure JavaScript sandbox, based on SES
Apache License 2.0
829 stars 72 forks source link

importNowHook optimizations #2466

Open boneskull opened 1 month ago

boneskull commented 1 month ago

per @naugtur's comment:

not all of these must make sense, I'm "thinking aloud":

compartmentDescriptors are not changing between calls to importNowHook, so most of this work could be hoisted out to the topmost maker function and only a lookup in a reindexed structure would be needed. On the other hand, the memory needed for that would be wasted most of the time as it's a very rare situation

I'd consider extracting it to a separate function findCompartmentContainingAbsolutePath

since this is not causing a module to be loaded, only redirecting - the further steps are going through a policy check anyway so skipping attenuators compartment in the lookup should be unnecessary as if any attenuators exist, a policy exists as well to prevent their code from being loaded by the compartment.

I'm not sure if this makes sense, but could policy be used to narrow down the search here? Take only the packages allowed by policy and look in their descriptors only.


This concerns the logic in makeImportNowHook, 'round about here:

https://github.com/endojs/endo/blob/84b451312b12cf6f239cae9cf484f2d5ad6f9d08/packages/compartment-mapper/src/import-hook.js#L655-L667

boneskull commented 1 month ago

To be addressed sometime after #2310 is merged