Conversation
|
Current dependencies on/for this PR: This comment was auto-generated by Graphite. |
PR Check ResultsEcosystem✅ ecosystem check detected no changes. BenchmarkLinuxWindows |
bf5fa37 to
46ea1ec
Compare
| } | ||
|
|
||
| /// Take the source code after the given [`Location`]. | ||
| pub fn after(&self, location: Location) -> &'src str { |
There was a problem hiding this comment.
😅 I don't feel too strongly about it. I just found that after works better with TextRange::up_to.
There was a problem hiding this comment.
Hah me neither. I had used until and after to mimic the iterator API but I genuinely don't feel strongly, trust you to do whatever makes sense.
| Message::from_diagnostic(diagnostic, path_lossy.to_string(), source, noqa_row) | ||
| Message::from_diagnostic( | ||
| diagnostic, | ||
| path_lossy.to_string(), |
There was a problem hiding this comment.
I wonder if we can apply some similar efficiency tricks to the path...? This also gets cloned and serialized once per diagnostic.
There was a problem hiding this comment.
Good idea. See #3904 (I created a PR on top to minimize the time spent rebasing the stacked PRs).
|
@MichaReiser Am I understanding correctly that this will also make it possible to use the errors cached on disk and displaying the source code without loading the file in memory at all? |
Yes, depending on your definition of loading the file in memory. But you could argue that the old implementation did this more efficiently. Previously,
But our main reason for storing the whole source code on
So in a sense, yes, this architecture avoids opening the source file and loading its content. But only because it loads the content from the cache ;) How does elmreview cache diagnostics? Does it re-read the content from the original file when rendering the diagnostic? |
b0f2c79 to
fb178f3
Compare
46ea1ec to
db04291
Compare
db04291 to
5e03d44
Compare

This PR stores the whole source text on
Messageso that it becomes possible to build up a code frame with dynamic context or show a diff for the code changes.The PR introduces two new data structures
SourceCode: Similar toLocator. It stores a reference to the source text and a reference to aLineIndex. The difference toLocatoris that theLineIndexis eagerly computed when creating theSourceCodeSourceCodeBuf: A owned version ofSourceCodethat uses anArc<str>for the source code to be cheaply cloneable.SourceCodeis used by bothSourceCodeBufandLocatorto implement the "resolution" logic that is shared between all three structs.Serialization
The
Messageserialization in ruff's cache skips over thesourcefield when serializing the messages to avoid serializing the contentntimes. Instead, the serializer computes the unique contents using the file name and stores each content only once.Benchmark
This change improves/regresses the runtime of some configurations slightly.
./target/release/ruff ./crates/ruff/resources/test/cpython/ -e./ruff-main ./crates/ruff/resources/test/cpython/ -e./target/release/ruff ./crates/ruff/resources/test/cpython/ -e --no-cache./ruff-main ./crates/ruff/resources/test/cpython/ -e --no-cache./target/release/ruff ./crates/ruff/resources/test/cpython/ -e --select=ALL./ruff-main ./crates/ruff/resources/test/cpython/ -e --select=ALL./target/release/ruff ./crates/ruff/resources/test/cpython/ -e --no-cache --select=ALL./ruff-main ./crates/ruff/resources/test/cpython/ -e --no-cache --select=ALL./target/release/ruff ./crates/ruff/resources/test/cpython/ -e --show-source./ruff-main ./crates/ruff/resources/test/cpython/ -e --show-source./target/release/ruff ./crates/ruff/resources/test/cpython/ -e --no-cache --show-source./ruff-main ./crates/ruff/resources/test/cpython/ -e --no-cache --show-source./target/release/ruff ./crates/ruff/resources/test/cpython/ -e --select=ALL --show-source./ruff-main ./crates/ruff/resources/test/cpython/ -e --select=ALL --show-source./target/release/ruff ./crates/ruff/resources/test/cpython/ -e --no-cache --select=ALL --show-source./ruff-main ./crates/ruff/resources/test/cpython/ -e --no-cache --select=ALL --show-source