matterhorn103 / quanstants

Intuitive and unastonishing physical quantities, units, constants, and uncertainties in Python
MIT License
1 stars 0 forks source link

Investigate possibility of reusing compound units #22

Closed matterhorn103 closed 4 months ago

matterhorn103 commented 4 months ago

Currently when the same two units are multiplied twice, two different instances of CompoundUnit are created, despite them being identical.

Ideally they would be reused to save memory, and possibly also to save time (if initialization can be avoided).

matterhorn103 commented 4 months ago

All strategies attempted so far result in the creation of compound units, and any methods that result in the creation of compound units e.g. most arithmetic, taking over twice as long.

The stumbling block is generating the hash, which is a very slow process currently, and the cost of doing that far outweighs the benefit of reusing the unit.

Memory is of course a concern (1 million quantities with the same unit require at least 80 GB for the units alone) but not sure the trade-off is worth it until the hashing time is reduced.

matterhorn103 commented 4 months ago

No need to do this now that things are evaluated lazily and compound units are fast.