← Back to Pull requests

[History Server] Cache JSON bytes and share the decoded snapshot via a weak pointer #5285

Closed
unknown closed this pull request without merging on Sep 18, 2026 01:31 UTC
View on GitHub
unknown unknown commented on Sep 14, 2026 04:46 UTC
Author

Why are these changes needed?

Based on the comment https://github.com/ray-project/kuberay/pull/5208#discussion_r3969000721, storing the Go struct directly is not a good choice, as there's no way for us to accurately estimate Go struct memory usage, and a fixed factor is not ideal.

This PR follows the method mentioned in https://github.com/ray-project/kuberay/pull/5208#discussion_r3969000721: it still stores the encoded JSON bytes in the LRU cache, alongside a weak pointer which points to the decoded snapshot, so concurrent requests can share the same decoded object rather than each request holding a separate copy. The byte budget goes back to counting the exact JSON length, so the 2.5x heap factor from #5208 is removed.

Related issue number

Follow-up: https://github.com/ray-project/kuberay/pull/5208#discussion_r3969000721

Labels

<!-- Please add the appropriate labels to this PR. -->

  • If this PR has user-facing changes that require documentation updates at release time, I have added the doc-updates-required label.

  • If this PR contains breaking changes, I have added the breaking-change label.
  • Checks

  • I've made sure the tests are passing.

  • Testing Strategy

  • - [x] Unit tests
    - [x] Manual tests
    - [ ] This PR is not tested :(

    <!-- If you selected "Manual tests" above, please fill in the section below. Otherwise you can remove it. -->

    Manual test instructions

    Columns are the average per GetSnapshot call: time, heap bytes allocated, and number of heap allocations.

    | Version | Cache stores | ns/op | B/op | allocs/op |
    |---|---|---|---|---|
    | Before #5208 (5914ac04^) | JSON bytes, decode per request | 3417 | 7512 | 112 |
    | master (#5208) | decoded struct, 2.5x heap estimate | 257.8 | 0 | 0 |
    | This PR | JSON bytes + weak pointer to shared decoded copy | 249.9 | 0 | 0 |

    Add following benchmark test to historyserver/pkg/historyserver/session_loader_test.go, and run with:

    go test -run xxx -bench GetSnapshot_Parallel -benchmem ./pkg/historyserver/
    

    func BenchmarkGetSnapshot_Parallel(b *testing.B) {
    	key := testClusterSessionKey()
    	sl := NewSessionLoader(&fakeProcessor{}, context.Background(), time.Minute, 100, 0, 0)
    	if err := sl.putSnapshot(key, richSnapshot(key)); err != nil {
    		b.Fatalf("putSnapshot: %v", err)
    	}
    	b.ReportAllocs()
    	b.RunParallel(func(pb *testing.PB) {
    		for pb.Next() {
    			snap, _ := sl.GetSnapshot(key)
    			runtime.KeepAlive(snap)
    		}
    	})
    }
    

    Diff: 315 lines (+236 / -79) across 3 files Reviewer: win5923 Review duration: 5564m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.40) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 315 lines diff across 3 files
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.344
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #5285"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 40.4% (MEDIUM) · Higher = larger blast radius
    40.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17.5% · Safe to merge
    17.5%