From de79f2a1d493515114f0e74ca3b5c86bcdfd334e Mon Sep 17 00:00:00 2001 From: David Aurelio Date: Sat, 2 Mar 2019 12:39:37 -0800 Subject: [PATCH] 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 --- yoga/Yoga.cpp | 11 ++++++++++- yoga/Yoga.h | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index 27072c1c..94d9a602 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -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"); } diff --git a/yoga/Yoga.h b/yoga/Yoga.h index 753a2f9f..7132a934 100644 --- a/yoga/Yoga.h +++ b/yoga/Yoga.h @@ -411,6 +411,8 @@ WIN_EXPORT float YGRoundValueToPixelGrid( const bool forceCeil, const bool forceFloor); +void YGSetUsedCachedEntries(size_t); + YG_EXTERN_C_END #ifdef __cplusplus