Initial layout-selection for structs
commit4516f2c01e1acafdb5cac96bc1bebb04f64e368b
authorShaunak Kishore <kshaunak@fb.com>
Mon, 22 Mar 2021 13:20:31 +0000 (22 06:20 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Mon, 22 Mar 2021 13:23:41 +0000 (22 06:23 -0700)
tree58dfa92dddad9d390c12e51d64fa103dbc8836bf
parentc9ca12827fc78e516314c2cab45220521f903cfe
Initial layout-selection for structs

Summary:
Here is how the overall algorithm works:

1. We initialize a UnionFind data structure on array sources. It only includes sources which have candidate struct layouts.
1. We iterate over sinks. For any sink that is a "merge point", we union the incoming sources together.
1. We iterate over disjoint sets of sources. If there's a candidate struct layout for the entire set, and if the overall probability of escalation is low, we assign all sources and sinks in that set to that layout.

The key decision here is the "merge point" decision in step 2. Here is how that decision works:
1. If an incident source has no candidate struct layout, the sink is not a merge point.
1. If too many distinct string keys are seen at that source, the sink is not a merge point.
1. Otherwise, we construct a UnionFind instance for keys seen at that sink. We union keys if they appeared together in some array that reached that sink.
1. The sink is a merge point iff all keys end up in the same disjoint set.

As you can see, UnionFind is an algorithm so nice, we used it twice.

This code is flag-guarded right now because it doesn't work with jumpstart, but we can still run local test cases. We'll land it and optimize the generated code while adding jumpstart support concurrently. To ease development, I've updated hhvm_wrapper.php with parameters that should be closer to our final configuration.

Reviewed By: colavitam

Differential Revision: D27096466

fbshipit-source-id: a20a48af7877eef620574f4134710c01960c4e41
hphp/runtime/base/bespoke/layout-selection.cpp
hphp/runtime/base/runtime-option.h
hphp/tools/hhvm_wrapper.php