jalberse / shimmer

Physically based rendering in Rust
Apache License 2.0
33 stars 0 forks source link

(Maybe) Switch from once_cell to compile-time generation of named spectra and rgb-to-sectra tables #20

Closed jalberse closed 3 months ago

jalberse commented 9 months ago

Currently, I use once_cell to lazily generate named spectra. I also plan to do the same for the rgb-to-spectra tables (though that should be mostly loading them from predefined binary files using the rgbtospectra crate, but we'll see).

once_cell allows lazy evaluation that's thread-safe. It does require runtime overhead to (1) check for initialization and (2) initialize on first get and (3) match to get the correct data (I access the static variables via an enum currently, maybe there's a better way).

But RwLock (and mutex) are now const functions, meaning a static RwLock should be possible. I think this can be a replacement for lazy evaluation via once_cell, and we can instead use a RwLock and initialize the data at compile time. This saves having to check if it's initialized.

I'm not totally sure about this change, and I'm just going to use once_cell for now because I know how it's done, but I might want to make this change later.

jalberse commented 9 months ago

Though just because RwLock is a const fn, doesn't mean that anything we want to evaluate can be a const function. So unless we can get initialization to work at compile-time, then once_cell may be better.

When the system is more built-out I can revisit this.

jalberse commented 3 months ago

This probably isn't worth it. I don't see this incurring significant costs in benchmarks.