Skip to content

Tweak performance of quantify lib #32

@cblock

Description

@cblock

Hi Andrew,

currently I'm in the process of performance tweaking quantify_mongoid. That's when I noticed that Quantity#to_si and Unit#for operations are very slow. Tracking it down further (see https://github.com/cblock/quantify/tree/perf/perf) I found out that Dimensions#to_hash is both expensive in terms of cpu cycles and frequently called when invoking #to_si on a quantity.
Same goes for Module#escape_multi_word_units when invoking Unit#for on complex units.

My feeling is that, e.g. #to_hash could be momoized but when I started refactoring I also noticed that you allow reconfiguration of dimensions and units during runtime. This in turn makes it necessary to invalidate memoized values for #to_hash and other operations.

So my question is: Is it really necessary to support reconfiguration during runtime? I found that you use that in quantify_amee to unregister some units. But wouldn't it be better to load everything once during initialization (e.g. into Singletons) and then not change it until app shuts down?

Also: I'm happy to help out refactoring quantify lib into that direction but I'm not too sure where to start. Any suggestions are greatly appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions