Add bespoke support for APC
commit7aac7fcd37b9e744c65a1bea66459ac60f44594d
authorShaunak Kishore <kshaunak@fb.com>
Tue, 4 May 2021 16:50:21 +0000 (4 09:50 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Tue, 4 May 2021 16:51:35 +0000 (4 09:51 -0700)
tree2aae05bd727ced63463efd60df91bb42518f22e4
parent3b21bcf2fd78792ada7ea1232c9690c232741f11
Add bespoke support for APC

Summary:
Support layout profiling for all static and uncounted arrays in APC. We key the profile of an APC dicts by a hash of the dict's keys. Doing so causes us to assign the same layout to all dicts with the same struct-like shape.

We profile an APC array on fetch. Note that we count a fetch as a sample for every subarray reachable from the root array that we're returning, because we don't have a later opportunity to make the sampling decision. That's why, when we first store the array in APC, we need two copies: a deeply-vanilla version, and a deeply-logging one. To help us build these variants, we have a core mapping helper, "makeAPCBespoke", which applies a given layout-selection mode to every array recursively contained within the root.

The core of this diff is the implementation of makeAPCBespoke. It's quite tricky, because we want to share as many subarrays between different results as possible, and we also want it to be decently fast. We specialize this helper on each vanilla array input type. We can assume for performance that almost all arrays being processed here are vanilla arrays, but we can't assume that for correctness; instead, we escalate bespoke arrays before passing them to the specialized helper. There are a variety of tricks we have to play to sample the behavior of logging array results here correctly - see inline comments.

Reviewed By: colavitam

Differential Revision: D27899293

fbshipit-source-id: f1528f79bd729d146e0564331ddae5cfc3fd2cf1
17 files changed:
hphp/runtime/base/apc-bespoke.cpp [new file with mode: 0644]
hphp/runtime/base/apc-bespoke.h [new file with mode: 0644]
hphp/runtime/base/apc-handle.cpp
hphp/runtime/base/apc-handle.h
hphp/runtime/base/apc-stats.cpp
hphp/runtime/base/apc-typed-value.cpp
hphp/runtime/base/apc-typed-value.h
hphp/runtime/base/bespoke/layout-selection.cpp
hphp/runtime/base/bespoke/logging-array.cpp
hphp/runtime/base/bespoke/logging-array.h
hphp/runtime/base/bespoke/logging-profile.cpp
hphp/runtime/base/bespoke/logging-profile.h
hphp/runtime/base/concurrent-shared-store.cpp
hphp/runtime/base/execution-context.cpp
hphp/runtime/base/runtime-option.h
hphp/runtime/base/tv-uncounted.cpp
hphp/runtime/vm/jit/array-layout.cpp