perf: lazy operations on sorter#434
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
@H4ad how does this affect search time? |
Could you please add this as a last function call in @allevo maybe we should expose a simple import { create, insertMultiple, ensureSort } from '@orama/orama'
const db = await create({ ... })
await insertMultiple(db, [...])
await ensureSort(db)^ super bad DX, written it down not to forget about it |
|
@micheleriva Only worth adding if you know the users never call About the |
|
The PR looks fine to me in general, even though I don't really like the As @H4ad pointed out, doing it within If we move the |
|
What about this:
what do you think? |
|
So we handle this outside of the sorter? Ok, it makes sense to me. @H4ad Can you please implement the aforementioned changes? |
|
@H4ad we didn't plan this activity, but we'll reward a small bounty anyway as soon as it lands. Your work is immensely appreciated |
|
/tip $70 |
|
As soon as I have time I will implement these changes, probably today. |
|
💡 @H4ad submitted a pull request that claims the bounty. You can visit your org dashboard to reward. |
|
@micheleriva I read the suggestions but it doesn't make sense to have the If I define the Or, I keep the current changes and I also add a property called |
|
@H4ad The idea is that you don't really remember which properties are sorted and which are not. It's easier to just assume that when a document is inserted/updated/removed all properties are unsorted. The rationale behind this is that unliked other system Orama is optimized to be used in a two phases: "insert all documents" and then "search" (and the DB in this phase should not be modified anymore). |
|
@ShogunPanda I agree with your design of Orama and this change will not affect that. Calling Doing this approach will just make the On the optimization side, adding it to |
|
If you don't want to add to Orama, you can add it to the sorter, eventually. |
|
@ShogunPanda Added isSorter to I also removed the export of |
|
I also transform the remove operation into lazy one, before: Now: |
| sorter.sortablePropertiesWithTypes[path] = type | ||
| sorter.sorts[path] = { | ||
| docs: {}, | ||
| docs: new Map(), |
There was a problem hiding this comment.
I fear we can't use maps here as they're not directly serializable to JSON. @allevo, @ShogunPanda please correct me if I'm wrong
There was a problem hiding this comment.
yes correct
% node
Welcome to Node.js v20.2.0.
Type ".help" for more information.
> JSON.stringify({ a: new Map() })
'{"a":{}}'
> a = new Map()
Map(0) {}
> a.set('a', 0)
Map(1) { 'a' => 0 }
> JSON.stringify({ a })
'{"a":{}}'
> a
Map(1) { 'a' => 0 }
>
A custom toJSON function is required here.
There was a problem hiding this comment.
It's quite strange that our tests couldn't identify this. We need to fix that sooner or later
There was a problem hiding this comment.
|
Other than things that @micheleriva outlined, looks good to me. |
|
Looks good to me. @allevo / @ShogunPanda would you be so kind to test this locally with serialization/deserialization before merging? |
|
@micheleriva I'm currently full on my list. @allevo can probably test this quicker. |
allevo
left a comment
There was a problem hiding this comment.
HI! Thanks for your contribution.
I'm checking the code.
Does this change also affect the documentation?
| return | ||
| } | ||
|
|
||
| sorter.language = language |
There was a problem hiding this comment.
I don't think we want to support a language change during the insertion: the language remains the same as the DB creation.
There was a problem hiding this comment.
This is what Orama does already: https://github.com/oramasearch/orama/blob/main/packages/orama/src/components/sorter.ts#L111
But I change the default to get from tokenizer.
|
Another tip: could you ensure after the |
|
@allevo We can do that, but doesn't make sense on the optimization side: #434 (comment) And this change doesn't change the documentation. |
|
LGTM ! |
micheleriva
left a comment
There was a problem hiding this comment.
LGTM. Amazing job @H4ad
|
@H4ad: You just got a $70 tip! 👉 Complete your Algora onboarding to collect your payment. |
|
🎉🎈 @H4ad has been awarded $70! 🎈🎊 |

Well, instead of sorting every time you insert an item, now it only sort when you need to search, this speedup up the insert by A LOT.
To compare, the following code went from
1m 7sto1swith this change:Before this change:
Now:
Also, this new change also fix the #348, instead of hours, it took just a minute to run.
/claim #434