Repository navigation
Cache verified remote contiguous length - #810
marcus-pousette-hp wants to merge 4 commits into
Conversation
| const length = this.remoteBitfield.findFirst(false, this._remoteContiguousLength) | ||
| // Cache the verified extent so repeated reads do not rescan the same bitfield run. | ||
| if (length > this._remoteContiguousLength) this._remoteContiguousLength = length | ||
| return length |
There was a problem hiding this comment.
Having a getter with side effects is tenuous as getters imply only reading values.
Can we apply these checks when the remote bitfield is mutated (onbitfield & onrange)? This will also ensure the value is updated when we have more info from the remote. Otherwise accessing _remoteContiguousLength directly will have less information than if calling .remoteContiguousLength. We also could explore replacing _remoteContiguousLength to be .remoteContiguousLength, though maybe should be a separate PR to keep scope simple and incremental.
Regarding that, could you add a test for a scenario where onbitfield updates _remoteContigousLength and later a broadcastRange() is called for the same peer but is skipped via the check here:
Line 650 in d53c83b
|
|
||
| const peer = getPeer(b, a) | ||
|
|
||
| peer.remoteFork = b.core.state.fork |
There was a problem hiding this comment.
Setting the fork isn't necessary as they both start at 0.
Before:
After:
Local bench test from before and after patch.
PR was Co-authored with AI.