Skip to content

bench: run FindByte across block-sized buffer - #34046

Closed
l0rinc wants to merge 1 commit into
bitcoin:masterfrom
l0rinc:l0rinc/findbyte-bench
Closed

l0rinc wants to merge 1 commit into
bitcoin:masterfrom
l0rinc:l0rinc/findbyte-bench

Conversation

@l0rinc

@l0rinc l0rinc commented Dec 10, 2025 •

Copy link
Copy Markdown
Contributor

The benchmark was updated to start from different file positions and iterate with a stride of ~32kb to exercise a few "random" places.

Found while reviewing #34044

Note: this PR started off as making FindByte more realistic, but based on #34044 (comment) I decided to remove it, and after #34046 (comment) it was reverted to its original state

@DrahtBot DrahtBot added the Tests label Dec 10, 2025
@DrahtBot

DrahtBot commented Dec 10, 2025 •

Copy link
Copy Markdown
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/34046.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK maflcko, Raimo33
Concept NACK sipa

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

@DrahtBot

Copy link
Copy Markdown
Contributor

🚧 At least one of the CI tasks failed.
Task macOS native: https://github.com/bitcoin/bitcoin/actions/runs/20113425463/job/57716719394
LLM reason (✨ experimental): bench_sanity_check test segfault caused CI failure.

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

Comment thread src/bench/streams_findbyte.cpp Resolved
@Raimo33

Raimo33 commented Dec 11, 2025

Copy link
Copy Markdown
Contributor

Code Review ACK 031ee0b22c4ee4f04f66cb8f0be534b404dbe73c

The new benchmark is more realistic

@l0rinc
l0rinc force-pushed the l0rinc/findbyte-bench branch from 031ee0b to 464ee9e Compare December 11, 2025 12:14
Comment thread src/bench/streams_findbyte.cpp Resolved

@maflcko maflcko left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm 464ee9e26f7851ff27c2d18f807ae64c8dd0fc62, but I'd prefer to not use the low-level buffer writing questionable "optimization"

The current benchmark doesn't represent a realistic scenario:
* it only checks 200 bytes, while in reality we have 8 MB: https://github.com/bitcoin/bitcoin/blob/2c44c41984e0a170cf38d595635a9e861854573c/src/validation.cpp#L5009
* it only checks the very last position (which is basically the missing case), while in reality it's a circular buffer, so the magic bytes can be anywhere
* plain array was needlessly serialized instead of written directly

The benchmark was updated to start from different file positions and iterate with a stride of ~32kb to exercise a few "random" places.
@maflcko

maflcko commented Dec 11, 2025

Copy link
Copy Markdown
Member

review ACK 93941dc 🐪

Show signature

Signature:

untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: review ACK 93941dc74be8817463e024e5aa11ed0638fdc9f3 🐪
Yt2ihRdgRtgrO4buTQEVh9tmEonYfAwnXmc8GMkuzgWbdXqsilW8jJP/6QMesry75/BUwnPrr7ognDzINKfsAw==

@Raimo33

Raimo33 commented Dec 11, 2025

Copy link
Copy Markdown
Contributor

re ACK 93941dc

@l0rinc l0rinc closed this Dec 11, 2025
@l0rinc l0rinc reopened this Dec 11, 2025
@l0rinc

l0rinc commented Dec 11, 2025

Copy link
Copy Markdown
Contributor Author

(close/open dance to fix boost download issue)

@l0rinc
l0rinc force-pushed the l0rinc/findbyte-bench branch from 93941dc to 35386df Compare December 14, 2025 17:03
@l0rinc l0rinc changed the title bench: run FindByte across block-sized buffer bench: remove FindByte benchmark Dec 14, 2025
@l0rinc

l0rinc commented Dec 14, 2025

Copy link
Copy Markdown
Contributor Author

Decided to remove this benchmark instead of updating it - seeing that actual reindex got slower, while even the updated benchmark showed a speedup, since current blocks always contain the header in the first position.

@sipa

sipa commented Dec 14, 2025

Copy link
Copy Markdown
Member

Concept NACK.

The existence of a benchmark does not imply it's worth efforts for improving the code further. It's still useful to see it doesn't regress.

It's not that we don't care about FindByte's performance. It would probably be unacceptable to make it 100x slower. But as-is, it's good enough.

@l0rinc
l0rinc force-pushed the l0rinc/findbyte-bench branch from 35386df to 93941dc Compare December 14, 2025 18:17
@l0rinc

l0rinc commented Dec 14, 2025 •

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback @sipa, I have reverted the previous version which checks multiple positions.

@l0rinc l0rinc changed the title bench: remove FindByte benchmark bench: run FindByte across block-sized buffer Dec 14, 2025
@l0rinc

l0rinc commented Dec 15, 2025

Copy link
Copy Markdown
Contributor Author

I'll try something else, closing for now

@l0rinc l0rinc closed this Dec 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants