Instance.GetFunction Cache#294
Conversation
|
Hi @martindevans, sorry for the delay in reviewing this! These changes look good, only I'm having a hard time thinking about the real world use case that would necessitate the caching in the API, as I think the typical use case would, at worst, simply store the returns of I would imagine that it's fairly rare to call Would you mind sharing a usage pattern that you think would directly benefit from having an internal synchronized cache? |
|
The various performance improvement PRs I've been submitting recently are all driven by a game I'm working on at the moment, which allows users to write code (in WASM) to run in game units. There may be around 100 different WASM instances all running in the game, all of which require various calls every frame. The game runs a "sim" as quickly as possible and then saves the replay, so speed is very important! Initially I was not saving the results of |
…` methods. This reduces a benchmark fetching a function 1,000,000 times from 300ms to 30ms.
cfb48d1 to
2f71d6d
Compare
|
It's good to know these can be cached, but I can see the hesitation since the optimisation mustn't negatively affect other use cases, such as a single module with a large number of exports and infrequent usage from taking up more memory when idle. |
|
These objects are already cached in the If there's interest in merging this, a hard cap could be added (e.g. stop adding to the cache once it has 1000 items in it) to handle truly extreme cases. The same logic should probably be applied to other caches in that case though. |
Added a cache into the
Instance.GetFunctionandInstance.GetMemorymethods. This reduces a benchmark fetching a function 1,000,000 times from 300ms to 30ms.