Repository navigation
Conversation
|
The issue with this is now there's no way to opt out of ast caching. It's pretty reasonable to assume ast caching is a net benefit when parsing from disk, but not necessarily when parsing code that's already in memory. Depending on how mecha is configured, the extra sha256 and I/O overhead could perform worse than simply re-parsing what's already in memory, for example a function tree generated by a plugin with tons of really small files. Of course in most cases it's better to generate code as plain mcfunction, this way you can just configure your pipeline to not process the generated code through mecha at all, but I understand this might not always be practical. The good news is you can actually opt into ast caching for generated code by simply caching your generated code itself: n = 128
path = ctx.cache["thing"].get_path(f"{n=}")
if not path.exists():
path.write_text("".join([f"say {i}\n" for i in range(n)]))
ctx.data["demo:thing"] = Function(source_path=path)I'd recommend n = 128
with ctx.generate.draft() as draft:
draft.cache("thing", f"{n=}")
draft.data["demo:thing"] = Function([f"say {i}" for i in range(n)])Just note that right now with this approach you'll have to wait for the second rebuild for mecha to cache the ast. On the first build, drafted files are saved to the cache but their contents remain in memory so mecha's ast caching will not kick in. It's only starting from the second build that drafted files are loaded from disk, and only then will mecha attempt to cache the ast. But we could consider making |
This PR improve caching in mecha. Very useful if you generate bolt code in python like i do.
Here's an example with SimpleDrawer repo :
Left: Current mecha

Right: This PR
Redo of mcbeet/mecha#313