Experiement: Don't use Hashes in Coin Indexes #30
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hashes in index is bad
If you index a hash, you have a bad time, because you have to constantly restructure the B-Tree for the index.
This is because the hashes are random, and you may need to insert a node in-between two other hashes.
Object ID indexes would be good
If you use an increasing value, like ObjectId, then the B-Tree is basically append only
So I wanted to try changing the indexes to using ObjectIds for mintTxid and spentTxid
These properties are called _mintTx and _spentTx
Outcome
I did a quick test and this does appear to be about 20% faster out of the gate, and I have a feeling would retain it's syncing speed better than the hash index version.
Unfortunately, you lose some nice safety concerns, and I'm not sure of the structural integrity of mempool txs, since you'd need to make sure you didn't create coins with a new _mintTx that were previously minted.
Basically for each TX being created, you'd have to first make sure it wasn't already in the DB, if it is, use that _id
I think doing all those finds might actually still be faster than trying to using hashes for the mintTxid and spentTxid indexes.