This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Optimize Dex::generateProximityURIs().
ClosedPublic

Authored by sammccall on Oct 4 2022, 4:38 PM.

Details

Summary

Production profiles show that generateProximityURIs is roughly 3.8% of
buildPreamble. Of this, the majority (3% of buildPreamble) is parsing
and reserializing URIs.

We can do this with ugly string manipulation instead.

Diff Detail

Event Timeline

sammccall created this revision.Oct 4 2022, 4:38 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 4 2022, 4:38 PM
sammccall requested review of this revision.Oct 4 2022, 4:38 PM
adamcz added inline comments.Oct 5 2022, 9:34 AM
clang-tools-extra/clangd/index/dex/Dex.cpp
358

Is there a reason why you're doing this with manual manipulation of C-strings instead of StringRefs? I suspect passing StringRef here was not the problem, turning it into an std::string, from another std::string inside ParsedURI was.

Something like:
S = S.drop_while([](char c) { return c == ':'; });
S.consume_front(":");
if (S.consume_front("//")) {

S = S.drop_while([](char c) { return c == '/'; });
S.consume_front("/");

}

return S;

would be a bit more readable and less likely to have an off-by-one somewhere, imho.

sammccall updated this revision to Diff 465492.Oct 5 2022, 11:48 AM

pointers -> StringRef

clang-tools-extra/clangd/index/dex/Dex.cpp
358

I started with StringRef, and found it too awkward. I've changed it back, but I think it makes the main algorithm harder to understand (it's OK for findPathInURI, but mixing styles is more confusing for me).

StringRef is good at modelling range content or two pointers, but this algorithm is fundamentally about three pointers and uses (Begin, End) and (Path, End) equally. So you end up with too many degrees of freedom in the code and have to paper over with assertions.
And StringRef's API is mostly suited for manipulating content, not dealing with overlapping refs, so you end up with a mix of index+pointer+stringref that personally I find harder to understand.

I'm probably an outlier here, so converted it to use StringRef anyway

adamcz accepted this revision.Oct 6 2022, 6:25 AM
This revision is now accepted and ready to land.Oct 6 2022, 6:25 AM
This revision was automatically updated to reflect the committed changes.