3 ms·
Regex is a good example of where JIT can be a good idea for performance, but is it really 'single use'? A compiled regex object would presumably obey the lifeti
by MaxBarraclough 6y ago
Regex is a good example of where JIT can be a good idea for performance, but is it really 'single use'? A compiled regex object would presumably obey the lifetime rules of the host language. It might live as long as the host process, and be reused many times.
I wasn't very clear but I was really thinking of 'self-modifying' code, in contrast to conventional JIT as with regex (once generated, the binary is presumably never modified).
- vardump 6y ago> Regex is a good example of where JIT can be a good idea for performance, but is it really 'single use'? Ideally not, but take a look at real life code bases... Just like with SQL prepared statements. This kind of waste happens often due to reduced visibility. Abstraction layers are good at hiding details like construction cost. Repeated construction happens accidentally pretty easily.
- chrisseaton 6y agoSelf-modifying code is sometimes used to allow you to update an inline cache for a method dispatch as the program is running. Rather than having to recompile and produce new machine code to update an inline cache.
- MaxBarraclough 6y agoNeat idea. Presumably a dynamic JIT like HotSpot would use this technique. In C you can have a global function pointer, and mutate it, but presumably that still has an additional indirection compared to the self-modifying approach.
- chrisseaton 6y ago> Presumably a dynamic JIT like HotSpot would use this technique. Not in practice in HotSpot no, but it could do and similar VMs do. execute|write is not fashionable these days! Some systems enforce execute^write, so you can't do it.
- MaxBarraclough 6y ago> execute|write is not fashionable these days! Ah, of course! Hadn't thought of that.