This is an archive of the discontinued LLVM Phabricator instance.

[clang][objc] Speed up populating the global method pool from modules.
ClosedPublic

Authored by vsapsai on Sep 20 2021, 7:05 PM.

Details

Summary

For each selector encountered in the source code, we need to load
selectors from the imported modules and check that we are calling a
selector with compatible types.

At the moment, for each module we are storing methods declared in the
headers belonging to this module and methods from the transitive closure
of imported modules. When a module is imported by a few other modules,
methods from the shared module are duplicated in each importer. As the
result, we can end up with lots of identical methods that we try to add
to the global method pool. Doing this duplicate work is useless and
relatively expensive.

Avoid processing duplicate methods by storing in each module only its
own methods and not storing methods from dependencies. Collect methods
from dependencies by walking the graph of module dependencies.

The issue was discovered and reported by Richard Howell. He has done the
hard work for this fix as he has investigated and provided a detailed
explanation of the performance problem.

Diff Detail

Event Timeline

vsapsai created this revision.Sep 20 2021, 7:05 PM
vsapsai requested review of this revision.Sep 20 2021, 7:05 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 20 2021, 7:05 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
vsapsai updated this revision to Diff 374016.Sep 21 2021, 12:59 PM

Add a [failing] test case that checks handling methods from transitive modules.

vsapsai updated this revision to Diff 374017.Sep 21 2021, 1:08 PM

Simplify the test and make it less sensitive to what "method" clang selects to use.

vsapsai updated this revision to Diff 376084.Sep 29 2021, 6:01 PM

Visit all required modules and don't serialize methods from other modules.

vsapsai updated this revision to Diff 379516.Oct 13 2021, 1:37 PM

Try to preserve the order of methods when populating the global method pool.

This attempt is more successful at keeping the existing code working though I
still have 1 unexpected warning that requires further investigation.

vsapsai updated this revision to Diff 382477.Oct 26 2021, 3:42 PM

Rebase and update the commit message.

vsapsai retitled this revision from [Proof of concept] Serialize fewer transitive methods in `METHOD_POOL`. to [clang][objc] Speed up populating the global method pool from modules..Oct 26 2021, 3:44 PM
vsapsai edited the summary of this revision. (Show Details)
vsapsai added a subscriber: v.g.vassilev.

/cc @v.g.vassilev as he mentioned an issue with late-parsed templates can be similar to this one.

Lots of relevant discussion can be found at https://reviews.llvm.org/D109632 I'll add the link to it to the summary later, for now the summary is the same as commit message.

rmaz accepted this revision.Nov 3 2021, 8:09 AM
This revision is now accepted and ready to land.Nov 3 2021, 8:09 AM
vsapsai updated this revision to Diff 384606.Nov 3 2021, 3:50 PM

Rebase. Hopefully MLIR build is fixed and I'll be able to see relevant pre-merge check results.

Thanks for the review!