-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
One awesome aspect of Go is its excellent faciliities for embedding resources along with compiled executables. We piggyback on this capabilty in Regal to embed the entire bundle directory of the projects, containing ~300 Rego policies and a few JSON/YAML data files. This number will of course only grow with time. For pretty much all commands provided, our ideal is to drop out of Go as quickly as possible and do as much processing as we possibly can in the wonderful world of Rego ✨ But before we can do that, we must first compile the embedded bundle. This (compiling the Regal bundle) takes ~100 ms on my beefy M4 Max laptop, and of course considerably more on a more modestly specced machine, and dramatically more on under-specced CI runners.
Now to be clear: a few hundred milliseconds is nothing in terms of compilation time compared to many other languages, and this isn't generally a bottleneck for the typical OPA use case. However, for applications like Regal that essentially are customized OPA + embedded policies, what becomes a real problem is the fact that compilation needs to be done every time the executable runs. It doesn't matter that once we ship a binary, the embedded content is unchanged!
While this may be a non-issue for a long-running process like a server, even a few hundred milliseconds of delay before any actual processing takes place is a big deal for CLI applications running one-off commands, as they'll be perceived as sluggish. Now that the Rego evaluation is incredibly fast, this is quite a shame. So let's fix that if we can!
One obvious thing to try is of course to improve the performance of the compiler, and there's much to explore in that space (like e.g. concurrency #8060). For the embedded use case specifically, I'd however like to suggest that we also explore the option of allowing compiled state to be persisted and later loaded into the compiler in order to avoid doing much work at all. Essentially — we should allow advanced users and use cases a way to say "this is a bundle you have already compiled, load it without going through any compiler stages that aren't already in the compiled output". The most costly aspect of compilation is the many stages of rewriting Rego, and performing these stages should be entirely avoidable when provided policies where this has already been done. Some state — like the mapping of variable names to their rewritten aliases — is AFAIK not part of the compiler's output today. But we could easily include additional files containing the metadata necessary to quickly restore compiler state as part of the output from compilation when a "persist mode" toggle is set. Perhaps it could all fit in a bundle .manifest, or we'd add new files for this purpose. I'm sure we'll figure it out.
In my always humble opinion, this would make embedding Rego a truly amazing option for building OPA-powered CLI apps 😃
Metadata
Metadata
Assignees
Labels
Type
Projects
Status