Skip to content

Commit

Permalink
chore: set lockfile as having no content changes after write (denolan…
Browse files Browse the repository at this point in the history
…d#24023)

Slight perf regression when updating deno_lockfile in
denoland#23979
  • Loading branch information
dsherret committed May 29, 2024
1 parent 14a7460 commit a892353
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 8 deletions.
6 changes: 4 additions & 2 deletions cli/args/lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,15 @@ pub fn read_lockfile_at_path(filename: PathBuf) -> Result<Lockfile, AnyError> {
}

pub fn write_lockfile_if_has_changes(
lockfile: &Lockfile,
lockfile: &mut Lockfile,
) -> Result<(), AnyError> {
let Some(bytes) = lockfile.resolve_write_bytes() else {
return Ok(()); // nothing to do
};
// do an atomic write to reduce the chance of multiple deno
// processes corrupting the file
atomic_write_file(&lockfile.filename, bytes, cache::CACHE_PERM)
.context("Failed writing lockfile.")
.context("Failed writing lockfile.")?;
lockfile.has_content_changed = false;
Ok(())
}
4 changes: 2 additions & 2 deletions cli/lsp/language_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ impl LanguageServer {
// Update the lockfile on the file system with anything new
// found after caching
if let Some(lockfile) = cli_options.maybe_lockfile() {
let lockfile = lockfile.lock();
if let Err(err) = write_lockfile_if_has_changes(&lockfile) {
let mut lockfile = lockfile.lock();
if let Err(err) = write_lockfile_if_has_changes(&mut lockfile) {
lsp_warn!("{:#}", err);
}
}
Expand Down
2 changes: 1 addition & 1 deletion cli/module_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl ModuleLoadPreparer {

// write the lockfile if there is one
if let Some(lockfile) = &self.lockfile {
write_lockfile_if_has_changes(&lockfile.lock())?;
write_lockfile_if_has_changes(&mut lockfile.lock())?;
}

drop(_pb_clear_guard);
Expand Down
2 changes: 1 addition & 1 deletion cli/tools/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub async fn info(flags: Flags, info_flags: InfoFlags) -> Result<(), AnyError> {
// write out the lockfile if there is one
if let Some(lockfile) = &maybe_lockfile {
graph_exit_lock_errors(&graph);
write_lockfile_if_has_changes(&lockfile.lock())?;
write_lockfile_if_has_changes(&mut lockfile.lock())?;
}

if info_flags.json {
Expand Down
2 changes: 1 addition & 1 deletion cli/tools/installer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ async fn install_local(
crate::module_loader::load_top_level_deps(&factory).await?;

if let Some(lockfile) = factory.cli_options().maybe_lockfile() {
write_lockfile_if_has_changes(&lockfile.lock())?;
write_lockfile_if_has_changes(&mut lockfile.lock())?;
}

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion cli/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ impl CliMainWorkerFactory {
// For npm binary commands, ensure that the lockfile gets updated
// so that we can re-use the npm resolution the next time it runs
// for better performance
write_lockfile_if_has_changes(&lockfile.lock())?;
write_lockfile_if_has_changes(&mut lockfile.lock())?;
}

(node_resolution.into_url(), is_main_cjs)
Expand Down

0 comments on commit a892353

Please sign in to comment.