linkml / prefixmaps

Semantic prefix map registry
https://linkml.io/prefixmaps/
Apache License 2.0
11 stars 3 forks source link

Cut call time of `add_prefix()` by 99.8% #69

Closed sneakers-the-rat closed 6 months ago

sneakers-the-rat commented 6 months ago

Fix: https://github.com/linkml/prefixmaps/issues/68

Previously on perf hunting: we had stumbled across a method in the wild that seemed harmless enough, but upon getting closer it turned to attack and we saw that it was in fact O(2n^2) in disguise!!

On this episode: we propose a function-neutral change that looks the same to an external observer (eg. someone that calls and of the public methods combine(), prefixes(), or namespaces() methods directly) but internally within the add_prefix method we avoid set comprehensions that become very expensive as the namespaces or prefixes sets become large.

For Run on thelinkmltests--with-slow` enabled, no tests fail and... Current version: 156s (cumulative), 0.00580s per call This PR: 0.2s (cumulative), 7.75e-06s per call Change: -155.2s, 99.8% decrease