Skip to content

Slice: Add prefetch deduplication and freelist#12949

Draft
zwoop wants to merge 2 commits intoapache:masterfrom
zwoop:SlicePrefetch
Draft

Slice: Add prefetch deduplication and freelist#12949
zwoop wants to merge 2 commits intoapache:masterfrom
zwoop:SlicePrefetch

Conversation

@zwoop
Copy link
Contributor

@zwoop zwoop commented Mar 8, 2026

Track in-flight prefetches per remap instance using a mutex- protected set to prevent duplicate upstream requests. Recycle BgBlockFetch objects via a freelist under the same mutex. Fire the initial prefetch burst at header parse time so faster clients benefit sooner.

Co-Authored-By: Craig Taylor (who also did all the investigations"

Track in-flight prefetches per remap instance using a mutex-
protected set to prevent duplicate upstream requests. Recycle
BgBlockFetch objects via a freelist under the same mutex. Fire
the initial prefetch burst at header parse time so faster
clients benefit sooner.

Co-Authored-By: Craig Taylor (and research)
@zwoop zwoop added this to the 11.0.0 milestone Mar 8, 2026
@zwoop zwoop self-assigned this Mar 8, 2026
@zwoop zwoop added the slice label Mar 8, 2026
@zwoop zwoop marked this pull request as draft March 8, 2026 17:28
@zwoop zwoop requested a review from Copilot March 8, 2026 17:28
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enhances the slice plugin’s background prefetching by deduplicating in-flight prefetch requests per remap Config instance and reusing BgBlockFetch objects via a mutex-protected freelist. It also triggers the initial prefetch burst earlier (at server header-parse time) to improve time-to-first-byte for fast clients.

Changes:

  • Add schedule_prefetch() helper and shift initial prefetch scheduling to server response header parse time.
  • Update BgBlockFetch::schedule() to accept a URL-derived key and deduplicate via Config-owned tracking.
  • Add Config prefetch state: mutex + active-key set + freelist, with cleanup in Config destructor.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
plugins/slice/util.h Exposes schedule_prefetch() helper.
plugins/slice/util.cc Implements schedule_prefetch() and uses it for sliding-window prefetching.
plugins/slice/server.cc Schedules initial prefetch burst once response headers are parsed.
plugins/slice/prefetch.h Extends BgBlockFetch with config/key state and updated schedule() signature.
plugins/slice/prefetch.cc Implements dedup + freelist release/cleanup and integrates them into bg fetch lifecycle.
plugins/slice/Config.h Adds prefetch dedup/freelist data structures and APIs.
plugins/slice/Config.cc Implements prefetchAcquire() and calls cleanup from Config destructor (plus UNITTEST stubs).

Guard prefetchCleanup() with m_prefetch_mutex to prevent
data race with concurrent prefetchRelease() calls. Add unit
tests for prefetchAcquire() dedup semantics. Add missing
#include <string_view> to prefetch.h. Null-guard the result
of TSUrlStringGet() in schedule_prefetch() before constructing
std::string_view.
@zwoop
Copy link
Contributor Author

zwoop commented Mar 8, 2026

Addressed Co-Pilot's concerns.

@ezelkow1
Copy link
Member

ezelkow1 commented Mar 9, 2026

[approve ci]

@bryancall bryancall requested a review from traeak March 9, 2026 22:13
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.

3 participants