telus-agcg/wise_units

Redo wise_units' internals

Opened this issue · 0 comments

There are an existing number of problems that are currently more difficult than they should be to get through them:

  • using rational numbers for relevant values for measurements and units
  • custom units
  • parsing strings into Unit objects. Parsing strings to objects is super common and strongly related to the difficulty in doing custom units well. The current parser is ok, but it's a) about 40x slower than unitwise (the old Ruby library we've used), b) a lot of extra code to interpret the parser tokens, c) requires dynamically building at compile time (which is difficult, and even moreso for newcomers to the project) because custom units are not defined in code (they're in a text file that we read in and turn into code).
  • memoizing units (caching them after you've used them). ...or really just not duplicating data all over the place. Every time a Unit comes into existence, to do anything with it (ex. check compatibility with another unit) it has to traverse its internal list of units that it's built on (ex. an acre -> rods squared -> feet squared -> cm squared). This is super inefficient.