Skip to content

perf(session): reuse scoped reads within journal scans - #3673

Draft
chengqiangrd wants to merge 1 commit into
agentscope-ai:mainfrom
chengqiangrd:perf/session-scan-commit-cache
Draft

chengqiangrd wants to merge 1 commit into
agentscope-ai:mainfrom
chengqiangrd:perf/session-scan-commit-cache

Conversation

@chengqiangrd

@chengqiangrd chengqiangrd commented Oct 20, 2026 •

Copy link
Copy Markdown

AgentScope-Java Version

2.1.0-SNAPSHOT (PR base: main at 997c60ac; change commit: 9bd0e43f)

Description

Refs #3647

This revision avoids opening a fresh SQLite connection for every journal commit read without loading every row under a session prefix. It adds a synchronous, callback-scoped AtomicSessionStorage.withReadSession API with a backward-compatible default, then forwards that scope through LocalSessionStorage. The Windows SQLite backend reuses one connection and prepared statement while JournalSessionLog.scan follows the captured head's actual parent chain.

The reader is thread-confined and cannot be used after the callback returns. It intentionally does not promise snapshot isolation: each SQLite SELECT remains independently visible, so a concurrent writer is not held behind a long read transaction. Journal commits are immutable once linked, and the scan still validates chain continuity before returning its resource-free Iterable.

Compared with the current #3666 implementation, this does not list a prefix or build a map containing all commit payloads. Unreachable/orphan rows are not loaded. Up to 1 MiB of reachable raw commit JSON is retained for repeated iteration; overflow commits use the existing read path. This is not a total JVM memory limit: commit IDs, one materialized oversized row, deserialized events, and SQLite/JDBC buffers remain outside the budget. A single oversized row therefore still has to fit in memory.

Checksum validation remains enabled, and external payload blobs are still loaded and hash-checked on every iteration. The tests cover the default backend fallback, callback failure cleanup, escaped and cross-thread readers, exact/overflow cache boundaries, repeated and concurrent iteration, orphan rows, corrupt reachable commits, Windows file-handle release, and a concurrent SQLite writer.

Verification

  • GitHub CI: full clean verify passed on both Java 17 / Ubuntu and Java 17 / Windows.
  • Focused core/harness regression suite: 41 tests passed, 0 failures/errors/skips.
  • Spotless check: passed.
  • Real production path (LocalFilesystem → LocalSessionStorage → SQLite), 17 sessions × 6 commits, five fresh-process runs: median projection time was 1088 ms on main and 400 ms with this change. This is a local fixture, not a general performance guarantee.
  • The local Windows full run executed 2751 core tests with 0 failures, 2 errors, and 9 skipped; both errors were symlink tests blocked by this machine's missing symlink privilege. The independent Windows CI run passed them.
  • A local skip-tests verify reached Javadoc packaging but could not resolve several old Javadoc-plugin dependencies from the task-local Maven repositories. PR CI intentionally skips release-only Javadoc/source jars and passed on both platforms.

Checklist

  • Code has been formatted with mvn spotless:check
  • All tests are passing (mvn test) — full GitHub CI passed on Windows and Ubuntu
  • Javadoc comments are complete and follow project conventions
  • Related English and Chinese documentation has been updated
  • Code is ready for review — keeping this as a draft because the new public storage SPI and its no-snapshot contract need maintainer design review

@chengqiangrd
chengqiangrd force-pushed the perf/session-scan-commit-cache branch from 4bbba92 to 9bd0e43 Compare October 21, 2026 03:09
@CLAassistant

CLAassistant commented Oct 21, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@chengqiangrd chengqiangrd changed the title perf(session): reuse commit rows within journal scans perf(session): reuse scoped reads within journal scans Oct 21, 2026
@chengqiangrd
chengqiangrd force-pushed the perf/session-scan-commit-cache branch from 9bd0e43 to 36fc451 Compare October 29, 2026 06:24
@jujn jujn added the P2 重要不紧急 label Nov 3, 2026

This branch has not been deployed

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

Labels

P2 重要不紧急

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants