[racket-dev] Caching rendered icons
The time taken to render icons is becoming noticeable when DrRacket
starts up. I estimate ~300ms on my beefy laptop, and it will probably
double. 20ms per icon is fine until there are 50 icons and icon parts.
(This also would have happened if the icons were rendered from SVG in
Racket. The ominous-sounding ray tracer is actually quite fast, in part
now because of Typed Racket's optimizer.)
Programs like DrRacket should load cached icons instead of rendering
them at startup. I've had two ideas for this.
1. Runtime: Provide `bitmap-file-ref!'. The contract would be
bitmap-file-ref! : path-string? any/c (-> bitmap%) -> bitmap%
It works like `hash-ref!', but the "hash" is a subdirectory name, the
key is md5-ed to make a file name, and the thunk produces the icon.
Which directory would I put them in? Would I make a subdirectory of
'pref-dir? (Not 'temp-dir, because that might be the current directory.)
2. Compile time: Provide macros that render icons during expansion and
try to store them in the "compiled" directory. They expand to code that
loads the icon if the file exists; renders it otherwise. This turns
rendering into compiling and icons into program binaries, which Seems Right.
Is there a way to reliably get the "compiled" directory path during
expansion, and then load files from it at runtime? Can I ensure that
.PNG files are distributed automatically?
Neil T