this could be the bottleneck with nix …
naive solution
this requires at least 2 builds, ideally we need only 1 build
- on every compile round: split the build into objects
- round1
- compile every object: src + env + nixenv1 → obj1
- round2
- compile every object: src + env + nixenv2 → obj2
- condition: (src + env) is the same as in round1
- take obj1 and binary-patch the output paths for nixenv2
- obj1 + diff(nixenv1, nixenv2) → obj1patch2
- now, if obj1patch2 == obj2, then we have one “anecdote”,
where we can avoid the expensive recompilation by cheap binary-patching
and still get a lossless transformation from src to obj
- round3
- condition: (src + env) is the same as in round1 and round2
- now we have one “anecdote” where binary-patching has worked (round2).
we are feeling lucky, we skip the compilation, and go straight to binary-patching:- obj1 + diff(nixenv1, nixenv3) → obj1patch3
- obj2 + diff(nixenv2, nixenv3) → obj2patch3
- we generate both obj1patch3 and obj2patch3 to reduce the risk of collisions
- if obj1patch3 == obj2patch3, then yield the patched object,
otherwise recompile the object, and yield the compile result