Repository navigation
perf: reduce allocations when formatting and resolving files - #1354
Merged
Merged
Conversation
- Share the file bytes with plugins instead of copying them for each plugin and each stabilization pass. This changes `ProcessPluginCommunicatorFormatRequest.file_bytes` in dprint-core to `Arc<Vec<u8>>`, so dprint-core is bumped to 0.71.0. - Run the slow format warning in the file's own task instead of spawning a task for every file. - Share the document text and line index in the language server instead of copying them for each format request and change. - Don't copy the file texts to output a diff. - Don't allocate a list of plugin names for every file. - Don't allocate the name of every file separately from its path when reading a directory. - Do less work for each cli path argument.
…he bytes it reads
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.
Removes allocations found while reviewing the CLI's per-file paths. Nothing here was benchmarked; the changes remove copies by construction.
Formatting
Arc<Vec<u8>>) instead of copied for each plugin and each stabilization pass. This applies todprint fmt/check, the language server, the editor service,--stdin, and host formatting.select!instead of a spawned task, cancellation token, and path clone for every file (including files the incremental cache skips).Language server
Arc, so getting them for a format request doesn't copy them and a change only copies them when a request is still using them.File and plugin resolution
ResolvedPluginNamesthat refers to the plugins instead of allocating aVec<&str>for every file.DirEntry::Fileno longer has anameallocated separately from itspath.Vec, and in-scope literal paths are deduplicated without cloning.GlobPattern::deepest_base_dirgets the deepest base directory without cloning the pattern.dprint-core
ProcessPluginCommunicatorFormatRequest.file_bytesandFormatMessageBody.file_bytesare nowArc<Vec<u8>>so the CLI can give a process plugin the bytes without copying them. Bumped to 0.71.0.Behavior notes
run_parallelizedtakes&Path, &[u8], &[u8]instead of owned values.PluginsScope::formatresolves the plugins and writes its debug log when the future is first polled instead of when it's called.