tworld
tworld copied to clipboard
Code caching
Retain parsed {text} and {code} objects, globally. (And {gentext} when that's in place.) Key them by the raw text. Conveniently, parsing of these types never depends on world context.
When to discard cache entries? Least-recent-use, or hook into the instance pool? (We'd want to share entries across instances, so we can't just throw them away when the instance sleeps. But we don't want to keep entries around when all instances of a world are asleep.)
Note this is not the same as property caching. This doesn't care where the object came from, only what obj['text'] parses to.
Logically it would even make sense to cache these objects in the DB rather than in memory. However, there's no DB storage of ast.parse() trees, etc. Keeping pickled objects might be faster than repeated parsing, but I am skeptical.
Will eventually need a way to limit the cache pool size, on top of whatever other discard scheme we have.