Skip to content

Conversation

@JasirVoriya
Copy link
Contributor

Overview

  • Adds an O(1) start-index resolution when startOffset equals the block’s startOffset in LogCache.StreamCache#searchStartIndex.
  • Keeps the cache-hit path first; falls back to binary search only when neither cache nor block-start match applies.
  • No behavior change for sequential, cursor-based reads.

Motivation

  • First reads from a cached block often start at the block’s beginning. Previously, these took the binary search path.

Performance Impact

  • Cold-start/scan reads from block start:
    • Avoids O(log N) binary search and a small helper allocation.
    • Improves latency deterministically for large blocks.
  • Cursor-based reads:
    • Unaffected; cache hits remain O(1).

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

Add O(1) start-index when startOffset equals block start in LogCache.StreamCache#searchStartIndex. Keeps cache-hit path first; avoids binary search and allocation on cold-start scans. No behavior change for sequential cursors.
@superhx
Copy link
Collaborator

superhx commented Nov 7, 2025

@JasirVoriya Thank you for your PR. From the perspective of LogCache's usage scenarios, most calls to searchStartIndex will not hit startOffset == this.startOffset, so I think this optimization may not be very helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants