Another Code Cache approach for hex-emu (fex-emu derivative/fork)
As part of the work for fex/hex I implemented a multi-threaded, multi-process, just-in-time object code cache.
There were several challenges involved:
- Unlike aotir, the index cannot be sorted, so it got stored as a BST
- Similarly, the format had to be crash / atomic safe
- AOTOBJ was the goal, so relocations were needed
Key features include:
- Reading from the caches requires a shared lock
- Writing to the caches necessitates a unique lock and an advisory lock when resizing
- Index files are re-mapped as they grow in 64kb chunks
- Data files are mapped in chunks of 16 Megabytes
How does it perform?
No Cache:
$ time Bin/FEXLoader /bin/ls > /dev/null
real 0m0,277s
OBJCache:
$ time Bin/FEXLoader /bin/ls > /dev/null
real 0m0,029s
Native:
$ time /bin/ls > /dev/null
real 0m0,007s
Best OBJCache result so far:
$ time Bin/FEXLoader /bin/true > /dev/null
real 0m0,014s