-
Notifications
You must be signed in to change notification settings - Fork 117
perf(pm): add resolver provider foundation #3065
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
elrrrrrrr
wants to merge
9
commits into
next
Choose a base branch
from
perf/pm-review-resolver-provider-foundation
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+535
−148
Draft
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d4e87f7
fix(pm): make view registry test hermetic
elrrrrrrr fbbeb24
ci(pm): make defender setup best effort
elrrrrrrr 342a456
ci(pm): make bench cargo cache best effort
elrrrrrrr 5ddf314
perf(pm): add resolver manifest provider boundary
elrrrrrrr 7dcacb5
perf(pm): parse version manifests from vec buffers
elrrrrrrr b5e917d
perf(pm): extract requested core from full manifest parse
elrrrrrrr 054de62
perf(pm): add mock manifest provider
elrrrrrrr 0c295dc
perf(pm): fan out registry http clients
elrrrrrrr 9a331cb
perf(pm): add resolver pm wiring
elrrrrrrr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,23 +11,17 @@ | |
| //! Serialization and file writes run on a dedicated writer thread so manifest | ||
| //! persistence does not occupy async runtime workers or Tokio's blocking pool. | ||
|
|
||
| use std::fs; | ||
| use std::io::ErrorKind; | ||
| use std::path::{Path, PathBuf}; | ||
| use std::sync::Arc; | ||
| use std::sync::mpsc::{self, SyncSender, TrySendError}; | ||
| use std::sync::mpsc::{self, Sender}; | ||
| use std::thread::JoinHandle; | ||
|
|
||
| use async_trait::async_trait; | ||
| use serde::Serialize; | ||
| use utoo_ruborist::model::manifest::CoreVersionManifest; | ||
| use utoo_ruborist::service::{ManifestStore, VersionsInfo}; | ||
|
|
||
| use crate::util::json::{read_json_file, write_compact_sync}; | ||
|
|
||
| /// Opportunistic writer backlog. If disk stalls beyond this, new cache writes | ||
| /// are dropped instead of letting resolver memory grow without bound. | ||
| const MANIFEST_WRITE_QUEUE_CAPACITY: usize = 1024; | ||
| use crate::util::json::read_json_file; | ||
|
|
||
| pub struct DiskManifestStore { | ||
| cache_dir: PathBuf, | ||
|
|
@@ -112,13 +106,13 @@ enum ManifestWriteJob { | |
| } | ||
|
|
||
| struct ManifestWriter { | ||
| tx: SyncSender<ManifestWriteJob>, | ||
| tx: Sender<ManifestWriteJob>, | ||
| handle: JoinHandle<()>, | ||
| } | ||
|
|
||
| impl ManifestWriter { | ||
| fn spawn() -> Self { | ||
| let (tx, rx) = mpsc::sync_channel(MANIFEST_WRITE_QUEUE_CAPACITY); | ||
| let (tx, rx) = mpsc::channel(); | ||
| let handle = std::thread::Builder::new() | ||
| .name("utoo-manifest-store".to_string()) | ||
| .spawn(move || { | ||
|
|
@@ -138,14 +132,8 @@ impl ManifestWriter { | |
| } | ||
|
|
||
| fn enqueue(&self, job: ManifestWriteJob) { | ||
| match self.tx.try_send(job) { | ||
| Ok(()) => {} | ||
| Err(TrySendError::Full(_)) => { | ||
| tracing::debug!("Manifest store writer queue full; dropping cache write"); | ||
| } | ||
| Err(TrySendError::Disconnected(_)) => { | ||
| tracing::debug!("Manifest store writer stopped before accepting write"); | ||
| } | ||
| if self.tx.send(job).is_err() { | ||
| tracing::debug!("Manifest store writer stopped before accepting write"); | ||
| } | ||
|
Comment on lines
+135
to
137
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To maintain the non-blocking, "fire-and-forget" nature of the manifest store, use match self.tx.try_send(job) {
Ok(()) => {}
Err(mpsc::TrySendError::Full(_)) => {
tracing::debug!("Manifest store writer queue full; dropping cache write");
}
Err(mpsc::TrySendError::Disconnected(_)) => {
tracing::debug!("Manifest store writer stopped before accepting write");
}
} |
||
| } | ||
|
|
||
|
|
@@ -157,23 +145,27 @@ impl ManifestWriter { | |
| } | ||
| } | ||
|
|
||
| /// Apply the manifest-cache write policy on top of | ||
| /// [`crate::util::json::write_compact_sync`]: on `NotFound`, create the | ||
| /// parent directory once and retry — this is how the resolver hot path | ||
| /// avoids the up-front `mkdir` syscall on every warm-cache rewrite. All | ||
| /// errors are swallowed at the `debug` log level because the disk cache is | ||
| /// opportunistic; a dropped write only costs a future cache miss. | ||
| /// Serialize `value` and write to `path`. On `NotFound`, create the parent | ||
| /// directory and retry once — saves the mkdir syscall on every warm-cache | ||
| /// rewrite. Errors are logged at debug; disk cache is opportunistic. | ||
| fn write_json_sync<T: Serialize>(path: &Path, value: &T) { | ||
| match write_compact_sync(path, value) { | ||
| let bytes = match serde_json::to_vec(value) { | ||
| Ok(b) => b, | ||
| Err(e) => { | ||
| tracing::debug!("Failed to serialize {path:?}: {e}"); | ||
| return; | ||
| } | ||
| }; | ||
| match std::fs::write(path, &bytes) { | ||
| Ok(()) => {} | ||
| Err(e) if e.kind() == ErrorKind::NotFound => { | ||
| Err(e) if e.kind() == std::io::ErrorKind::NotFound => { | ||
| if let Some(parent) = path.parent() | ||
| && let Err(e) = fs::create_dir_all(parent) | ||
| && let Err(e) = std::fs::create_dir_all(parent) | ||
| { | ||
| tracing::debug!("Failed to create {parent:?}: {e}"); | ||
| return; | ||
| } | ||
| if let Err(e) = write_compact_sync(path, value) { | ||
| if let Err(e) = std::fs::write(path, &bytes) { | ||
| tracing::debug!("Failed to write {path:?}: {e}"); | ||
| } | ||
| } | ||
|
|
||
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change from a bounded channel to an unbounded one removes the safety mechanism that prevented memory growth when disk I/O stalled. Since the manifest store is opportunistic, it is safer to use a bounded
SyncSenderand drop writes when the queue is full to ensure memory usage remains bounded, especially given that the previous implementation explicitly handled this case.