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.
The
Source
structure stores an ownedString
for each individual line. This can cause many allocations for large documents. We regularly deal with 65 000 lines or more that only have a handful of diagnostics.This PR makes two changes:
Line{}
now only contains indices into the string. Both character and byte indices are calculated inSource::from
so the string storage can be sliced efficiently. You now have to go throughSource::get_line_text(Line)
to get the source text for a line. This commit still copies the text intoSource
but it does it in one allocation.Source
generic over the string storage. This does add some complexity, as the genericity also requires having an associated string storage type onCache
implementations. But, it lets you useArc<str>
as a storage type to avoid having to copy the whole source text into ariadne, or even&str
if you can guarantee the lifetime. TheFileCache
now no longer copies each file's contents immediately after reading it. Thesources()
function will use string references if possible. Only users of custom caches should be affected by this change.With these changes you can use ariadne without copying any strings, the only allocation is for computing line offsets (and for individual diagnostics of course).