Closed goto-bus-stop closed 1 year ago
Yeah I started out with type Storage = String
and got yelled at 🥲
Defaulting to String makes sense, mostly eases the upgrade path a bit for people currently writing Source
in return types or struct fields.
Thanks very much for the PR!
thanks for reviewing so fast! 🤩
Were you looking for a release with this in the near term, or are you ok to wait for a while?
It's not critical, so please pick as you see fit :)
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).