Rework Index preresolve algorithm
commitd38f6e1b759470e753c3c4bedc270885f2e6ae1c
authorRick Lavoie <rlavoie@fb.com>
Thu, 29 Apr 2021 04:57:39 +0000 (28 21:57 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Thu, 29 Apr 2021 05:00:36 +0000 (28 22:00 -0700)
tree32a0de2f49cfed80e49621e7a45e1226b72d3666
parent3153a3e81e64ac8ec3d31efa88ebf2e2d49ae7de
Rework Index preresolve algorithm

Summary:
When building the Index in HHBBC, most of the time (by far) is taken
up by the preresolve step. This step is responsible for building all
ClassInfos and populating them with all relevant information. This
includes flattening traits into their use classes, and flattening
other information into each class.

The reason this step takes so long is because its relatively
inefficient. For every class, it walks up its entire inheritance tree
and pulls in information for all parents/traits/interfaces. This is
wasteful because it performs a lot of duplicate work.

Rework the algorithm to be more iteratively. Instead of starting at
each class and working upward (many times), work downward. Start at
parent-less classes, calculate the information they would export to
their children/uses, then mark those classes as done. Now repeat the
process for any classes which have only done parents. Important the
information from parents, update it depending on the class, then
export that. Repeat this process until all classes have been
processed. This scheme is much faster because every class is only
processed once.

Differential Revision: D27994387

fbshipit-source-id: afc3bfd07e1230084aee464dbbd7530d9e755b59
hphp/hhbbc/index.cpp
hphp/hhbbc/parse.cpp
hphp/hhbbc/representation.h