Repository navigation
perf(alt-svc): prune only the requested origin during lookup - #2
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Every HTTP/3 discovery lookup currently prunes all cached origins while holding the cache mutex, including lookups for an absent origin. With 256 origins and eight alternatives each, this scans up to 2048 alternatives before looking up one key.
Prune only the requested origin during
AltSvcCache::candidates. Cache writes,len(),snapshot(), and network changes retain their full-cache cleanup. Lookups preserve origin normalization, expiration checks, candidate metadata, and failure backoff. Entries remain bounded by the configured capacity.Expired unrelated entries can remain resident until a cache mutation or observer reclaims them. Regression coverage checks that insertion reclaims those entries before evicting live origins, and that observers still report only live entries.
Measurements
The benchmark includes the production cache source directly to exercise the private lookup without adding a public API. Both binaries use the same benchmark source, locked dependencies, Cargo bench profile, and
--no-default-features --features http3on macOS aarch64 with Rust 1.99.1.b03ffd33e6e1a46efaee8edec6552f5fb17d6ae0(benchmark fixture only, production code unchanged from main).5706f5f589bc6c8bfe97cc6318ddaa642a51371d.empty_misssingle_hit64_origins_hit256_origins_hitfull_hitfull_missshared_full_hitshared_full_missfullmeans 256 origins with eight alternatives per origin.shareduses four threads sharing one cache. The single-origin median increases 2.7%, with overlapping interquartile ranges; the improvement is concentrated in populated-cache lookups.Reproduce each revision with:
Validation
Added regressions for target expiration, retained backoff metadata, reclamation before capacity eviction, and exact
len()/snapshot()results after misses. CI now compiles the benchmark in addition to the existing native, feature, MSRV, protocol, and package checks. Both push CI and PR CI passed all eight jobs at5706f5f589bc6c8bfe97cc6318ddaa642a51371d.Formatting and
git diff --checkcompleted. Regression suites are delegated to CI; local execution was limited to the benchmark.Related: #1.
Raw benchmark samples, grouped by process invocation
[ { "variant": "baseline", "round": 1, "ns_per_lookup_samples": { "empty_miss": [ 71.39792, 71.905, 73.20625, 74.84458, 77.07209, 79.23958, 79.43666, 103.59125, 226.97167 ], "single_hit": [ 98.16875, 100.36625, 101.30792, 102.83834, 104.21792, 104.80875, 105.29417, 105.88166, 106.38333 ], "64_origins_hit": [ 197.57417, 199.585, 199.77958, 206.55583, 207.35708, 208.74541, 209.85791, 211.65958, 213.47459 ], "256_origins_hit": [ 472.13167, 496.52125, 498.91, 501.92375, 504.39542, 511.81833, 516.19834, 518.07834, 527.12083 ], "full_hit": [ 1350.97209, 1377.82583, 1442.45708, 1744.52666, 1919.75792, 1941.63125, 1959.22208, 1970.0075, 1993.80459 ], "full_miss": [ 1247.33667, 1260.5025, 1262.34208, 1267.6075, 1279.90666, 1281.2399999999998, 1286.1275, 1312.70959, 1322.50959 ], "shared_full_hit": [ 2726.3714575, 2764.6520825, 2773.2460425, 2778.858645, 2779.63646, 2794.496145, 2837.841665, 2855.63354, 3101.65 ], "shared_full_miss": [ 2418.311145, 2430.908335, 2450.3372925, 2472.950105, 2473.6003125, 2488.642605, 2500.260625, 2525.683125, 2539.42302 ] } }, { "variant": "optimized", "round": 1, "ns_per_lookup_samples": { "empty_miss": [ 68.52875, 69.46667, 69.73834, 70.83416, 74.2675, 80.17333, 88.24917, 96.455, 114.975 ], "single_hit": [ 99.1075, 99.45333, 99.62625, 99.93417, 99.95292, 100.22417, 100.57125, 100.96208, 102.10584 ], "64_origins_hit": [ 99.55209, 100.48792, 100.82958, 101.05375, 101.47791, 101.61084, 101.71666, 101.71708, 103.26917 ], "256_origins_hit": [ 99.09917, 99.31791, 100.14458, 100.76417, 101.09083, 101.13, 101.25458, 102.30042, 103.32334 ], "full_hit": [ 132.94167, 133.07416, 133.18792, 134.17875, 134.765, 135.14291, 135.25417, 135.53084, 136.0325 ], "full_miss": [ 70.04625, 71.79875, 71.955, 72.22, 72.22167, 72.4625, 72.59458, 73.03042, 74.37958 ], "shared_full_hit": [ 575.7083325, 579.915, 586.87823, 587.8871875, 589.996875, 592.763125, 593.2309375, 596.9579175, 599.0421875 ], "shared_full_miss": [ 105.29125, 105.531355, 105.73021, 106.0629175, 106.0871875, 106.3395825, 106.3790625, 106.438335, 107.3151025 ] } }, { "variant": "optimized", "round": 2, "ns_per_lookup_samples": { "empty_miss": [ 67.03167, 67.3925, 67.41791, 67.45, 72.38084, 72.59041, 73.53833, 75.05542, 75.45375 ], "single_hit": [ 98.00875, 99.32583, 99.71375, 100.41708, 102.3475, 103.1725, 103.38333, 104.4325, 105.43542 ], "64_origins_hit": [ 98.72583, 99.43208, 99.975, 100.59167, 100.62792, 100.87542, 102.14542, 102.61666, 102.765 ], "256_origins_hit": [ 98.38833, 99.1375, 99.23958, 99.6475, 99.7675, 99.87208, 99.97709, 100.0825, 100.43416 ], "full_hit": [ 130.47375, 130.83459, 131.07166, 131.11542, 132.35792, 132.52, 132.59291, 133.66083, 135.43042 ], "full_miss": [ 71.23666, 71.27542, 71.38333, 71.54417, 71.58708, 71.85667, 72.59375, 72.81667, 73.38458 ], "shared_full_hit": [ 563.011355, 581.0104175, 582.369585, 590.0071875, 596.5191675, 603.194375, 604.366875, 614.5578125, 622.4014575 ], "shared_full_miss": [ 105.587085, 106.341145, 106.548855, 106.66229, 107.0239575, 107.0253125, 107.1209375, 107.5758325, 107.6841675 ] } }, { "variant": "baseline", "round": 2, "ns_per_lookup_samples": { "empty_miss": [ 73.95583, 75.19208, 75.80417, 76.0775, 76.66833, 77.35042, 77.74833, 78.8925, 79.99083 ], "single_hit": [ 95.19958, 95.27833, 95.4025, 95.53125, 96.63958, 96.73708, 96.73917, 97.01333, 97.15083 ], "64_origins_hit": [ 189.04375, 198.28917, 203.89208, 206.51125, 207.33083, 208.81042, 209.09542, 211.24958, 216.31375 ], "256_origins_hit": [ 464.10625, 472.73792, 476.32041, 482.79583, 487.60167, 488.05084, 501.55792, 506.9675, 507.48084 ], "full_hit": [ 1348.77584, 1358.49792, 1369.54375, 1375.22083, 1384.31959, 1385.50709, 1389.85084, 1402.72625, 1409.2475 ], "full_miss": [ 1247.99625, 1262.0637500000003, 1294.07583, 1350.38791, 1363.23083, 1405.28083, 1426.20875, 1577.08083, 1714.90375 ], "shared_full_hit": [ 2818.0784375, 3055.2578125, 3106.24302, 3107.051665, 3194.2504175, 3342.4760425, 3671.4670825, 3817.8232300000004, 3822.1465625 ], "shared_full_miss": [ 3624.00979, 3701.916665, 3712.568855, 3837.7475, 3876.475729999999, 3923.7982275, 4014.1990625, 4029.5464575, 4149.4392725 ] } } ]