Skip to content
This repository has been archived by the owner on Sep 30, 2023. It is now read-only.

[perf] optimise key index #48

Merged
merged 2 commits into from
Dec 18, 2021
Merged

[perf] optimise key index #48

merged 2 commits into from
Dec 18, 2021

Conversation

chrispanag
Copy link
Contributor

@chrispanag chrispanag commented Dec 18, 2021

There are two avenues for optimisation here:

  1. There is no need for a reversal and subsequently a copy of the original oplog.values array since this can be handled by a reverse for loop.
  2. Mainly, the handled value instead of being an array it can be an object, resulting in O(1) searches for handled values, instead of having to run a linear search each time an oplog value is added (which actually makes the creation of the index O(1/2 n^2 (n + 1)) - Ι think...)

Copy link
Contributor

@tabcat tabcat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great, thanks for opening this. if you could remove the ; semi-colons to match our standard code style that would be great.

src/KeyValueIndex.js Outdated Show resolved Hide resolved
const handled = {};
for (let i = values.length - 1; i >= 0; i--) {
const item = values[i];
if (handled[item.payload.key]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with 1.0 i want to make sure payload is always defined but this is fine for now, all store indexes are are like this atm.

@tabcat tabcat merged commit 5796883 into orbitdb-archive:main Dec 18, 2021
@chrispanag
Copy link
Contributor Author

looks great, thanks for opening this. if you could remove the ; semi-colons to match our standard code style that would be great.

Thanks for merging! Adding some prettier rules would be also nice to enforce these code style rules.

@tabcat
Copy link
Contributor

tabcat commented Dec 18, 2021

Adding some prettier rules would be also nice to enforce these code style rules.

Yes, in the main repo we have some eslint rules in the package. this package may eventually be a part of the main repo with the other stores and orbit-db-store.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants