for experimentation: configurable measure cache size

Summary:
@public

Allows to limit the number of measure cache entries used. This is purely for experimentation.

The measure cache uses about half of every `YGNode`. Reducing its size would allow us to reduce resident memory used by Yoga.

Reviewed By: SidharthGuglani

Differential Revision: D14279027

fbshipit-source-id: e0d22138230bee7fb129c193eb6e4085de02a36e
This commit is contained in:
David Aurelio
2019-03-02 12:39:37 -08:00
committed by Facebook Github Bot
parent 6368416178
commit de79f2a1d4
2 changed files with 12 additions and 1 deletions

View File

@@ -28,6 +28,15 @@ __forceinline const float fmaxf(const float a, const float b) {
using namespace facebook::yoga;
using detail::Log;
namespace {
size_t usedMeasureCacheEntries = YG_MAX_CACHED_RESULT_COUNT;
}
void YGSetUsedCachedEntries(size_t n) {
usedMeasureCacheEntries =
n == 0 || n > YG_MAX_CACHED_RESULT_COUNT ? YG_MAX_CACHED_RESULT_COUNT : n;
}
#ifdef ANDROID
static int YGAndroidLog(
const YGConfigRef config,
@@ -3871,7 +3880,7 @@ bool YGLayoutNodeInternal(
layoutMarkerData.maxMeasureCache =
layout->nextCachedMeasurementsIndex + 1;
}
if (layout->nextCachedMeasurementsIndex == YG_MAX_CACHED_RESULT_COUNT) {
if (layout->nextCachedMeasurementsIndex == usedMeasureCacheEntries) {
if (gPrintChanges) {
Log::log(node, YGLogLevelVerbose, nullptr, "Out of cache entries!\n");
}

View File

@@ -411,6 +411,8 @@ WIN_EXPORT float YGRoundValueToPixelGrid(
const bool forceCeil,
const bool forceFloor);
void YGSetUsedCachedEntries(size_t);
YG_EXTERN_C_END
#ifdef __cplusplus