dividab / uom

Extensible unit of measure conversion with type safety for typescript
MIT License
18 stars 1 forks source link

Serialize needs to be optimized #48

Closed marsve666 closed 4 years ago

marsve666 commented 4 years ago

Each time stringToUnit is called, the string-to-unit map gets rebuilt with a lowercase key. When parsing a lot of propertyvaluesets, it adds up and becomes slow. Possible solution, the caller have responsibility of giving the unit map in with lower case keys.

Slow part

jonaskello commented 4 years ago

Yes, we could just use the passed map without converting it to lowercase. Then it is the responsibility of the caller to keep have correct case in the map.

jonaskello commented 4 years ago

Since this will require a breaking change we might as well consider doing more than just removing the lowercase call. Perhaps we can do one of these:

(1) Remove the Serialize module and the 4 functions in it (serialize/deserialize unit and amount) (2) Move the functions for serialize/deserialize into the Unit and Amount modules and remove the Serialize mdoule (3) Keep the Serialize module and change the implementation only

jonaskello commented 4 years ago

@marsve666 Seems there are no strong opinions on this so perhaps the simplest way forward is to just keep the Serialize module the same in order to minimize breaking changes.

jonaskello commented 4 years ago

Fixed by #49