Permalink
Browse files

avoid reducing nonzero to zero in refcount profiles

Summary: If a value is often mostly uncounted, but very rarely counted, we still want to distinguish it with cases where the value is never counted during profiling.

Reviewed By: markw65

Differential Revision: D13283278

fbshipit-source-id: e3fd715ae6c69545c96e6e724025ccd1940d78d0
  • Loading branch information...
binliu19 authored and hhvm-bot committed Dec 2, 2018
1 parent bc68944 commit 172218ae17ba6be5f7b3fdfd95c7c10ef84732f6
Showing with 8 additions and 6 deletions.
  1. +4 −3 hphp/runtime/vm/jit/decref-profile.h
  2. +4 −3 hphp/runtime/vm/jit/incref-profile.h
@@ -81,11 +81,12 @@ struct DecRefProfile {
// distributions.
static void reduce(DecRefProfile& a, const DecRefProfile& b) {
auto const total = static_cast<uint32_t>(a.total + b.total);
if (total > std::numeric_limits<uint16_t>::max()) {
auto constexpr limit = std::numeric_limits<decltype(a.total)>::max();
if (total > limit) {
auto scale = [&] (uint16_t& x, uint64_t y) {
x = (x + y) * std::numeric_limits<uint16_t>::max() / total;
x = ((x + y) * limit + total - 1) / total;
};
a.total = std::numeric_limits<uint16_t>::max();
a.total = limit;
scale(a.refcounted, b.refcounted);
scale(a.released, b.released);
scale(a.decremented, b.decremented);
@@ -67,11 +67,12 @@ struct IncRefProfile {
// distributions.
static void reduce(IncRefProfile& a, const IncRefProfile& b) {
auto const total = static_cast<uint32_t>(a.total + b.total);
if (total > std::numeric_limits<uint16_t>::max()) {
auto constexpr limit = std::numeric_limits<decltype(a.total)>::max();
if (total > limit) {
auto scale = [&] (uint16_t& x, uint64_t y) {
x = (x + y) * std::numeric_limits<uint16_t>::max() / total;
x = ((x + y) * limit + total - 1) / total;
};
a.total = std::numeric_limits<uint16_t>::max();
a.total = limit;
scale(a.refcounted, b.refcounted);
scale(a.incremented, b.incremented);
} else {

0 comments on commit 172218a

Please sign in to comment.