Closed KarolS closed 2 years ago
Hello, @KarolS
I could see that you suggest to use addItem instead of addItems. But the way it is added the same. So your suggestion to remove duplicate check?
I'm not suggesting to use addItem
, I just changed it so that it maintains the itemIds
invariant. I don't know if it is used anywhere at all. If addItems
is optimized, then it can still be used just fine.
The main reason this.addItems
is slow is that this.hasItem
is slow, so I replaced it with much faster this.itemIds.has
.
oh, I see - thank you - will review it
Fixed
I'm sorry I'm saying this so late, but I only just checked.
The new implementation is still using a list and will still have quadratic performance. Why wasn't a set used?
Such a change will need bigger refactoring of this library. For now this project is almost freezed - hoping for better situation in future.
The only set that would be required to make it non-quadratic is itemIds, it would be a small and completely local change. What do you mean by "freezed"?
The only set that would be required to make it non-quadratic is itemIds, it would be a small and completely local change. This repo has a lot of references, so any change would need much testing If you need it in your project - you could download it locally and do changes you need.
What do you mean by "freezed"? The project has only small suport - no changes, no upgrade.
This loop: https://github.com/alpheios-project/alpheios-core/blob/master/packages/inflection-tables/lib/inflection-list.js#L36
has quadratic complexity, which makes the whole extension really slow. It can take several seconds for the definition to pop up.
Here is a partial flame graph:
Here is my suggestion how to fix it: