Page MenuHomePhabricator

Can we cache the result of executeModule to improve #invoke startup time?
Open, Needs TriagePublic

Description

Most invokes spend the vast majority of their running time inside executeModule, even if the user function executed by the invoke is very small. T357199 improved the performance of executeModule by ~15%, but articles with thousands of invokes are still spending a significant portion of their parse time in executeModule.

When there are this many invokes, usually it's a fairly small number of modules getting used repeatedly. Could we possibly cache the LuaSandboxFunction chunks returned by executeModule, instead of recomputing them every time?

The most obvious way to do this would keep the module scope between invokes, which is undesirable (T67258). I have experimented wrapping the entire module in a closure, which solves the most obvious scope-sharing issues (and speeds up #invoke calls by about 5x!!!), but this still can leak globals. If that approach doesn't work, what about modifying lua_newstate's memory allocator to "reset" the scope to a previous known/safe value?