halostatue / color

Color tools for Ruby.
Other
133 stars 41 forks source link

Remove startup overhead? #30

Open mperham opened 8 months ago

mperham commented 8 months ago

The colors gem is slow to require because it generates a lot of constants and structures at boot time. For instance:

https://github.com/halostatue/color/blob/ecd635f5db7fb67e03dc737cb75fb862323ebd6e/lib/color/rgb/colors.rb#L9

Would it be possible to lazy load these named constants and hashes only upon first access?

halostatue commented 8 months ago

Yes, but…

I’m caught in a bit of a spiral with this library. There are a number of fixes that should be applied to it (missing features with at least two different competing and incompatible implementations, a bit of modernization, possible performance optimizations beyond lazy boot, etc.) and every time I get started…I can't get motivated to complete any of it. It needs a new version that sheds a lot of the old version baggage (there is no reason to continue supporting anything less than Ruby 2.7 with new releases) and approaches the problem differently (at this point, if I were to approach this, I would look at it with oklab as the core representation and everything else would be put through colourspace transformations).

I really should put this up for adoption, but there's a part of me that isn't quite ready to give it up unless and until I can get it onto a good path moving forward.

All of that to say…I would take a PR that does this, but I can't really speak to the overall releasability of the code without taking time that I don’t currently have.