[K/N][New MM] Rare GC calls to optimize swiftinterop benchmarks
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include <cstddef>
|
||||
|
||||
#include "Utils.hpp"
|
||||
#include "Types.h"
|
||||
|
||||
namespace kotlin {
|
||||
|
||||
@@ -52,12 +53,16 @@ public:
|
||||
void SetAllocationThresholdBytes(size_t value) noexcept { allocationThresholdBytes_ = value; }
|
||||
size_t GetAllocationThresholdBytes() noexcept { return allocationThresholdBytes_; }
|
||||
|
||||
void SetCooldownThresholdUs(uint64_t value) noexcept { cooldownThresholdUs_ = value; }
|
||||
uint64_t GetCooldownThresholdUs() noexcept { return cooldownThresholdUs_; }
|
||||
|
||||
void SetAutoTune(bool value) noexcept { autoTune_ = value; }
|
||||
bool GetAutoTune() noexcept { return autoTune_; }
|
||||
|
||||
private:
|
||||
size_t threshold_ = 0;
|
||||
size_t allocationThresholdBytes_ = 0;
|
||||
uint64_t cooldownThresholdUs_ = 0;
|
||||
bool autoTune_ = false;
|
||||
};
|
||||
|
||||
|
||||
@@ -102,7 +102,8 @@ void gc::SameThreadMarkAndSweep::ThreadData::SafePointRegular(size_t weight) noe
|
||||
size_t counterOverhead = gc_.GetThreshold() == 0 ? safePointsCounter_ : safePointsCounter_ % gc_.GetThreshold();
|
||||
if (threadData_.suspensionData().suspendIfRequested()) {
|
||||
safePointsCounter_ = 0;
|
||||
} else if (counterOverhead + weight >= gc_.GetThreshold()) {
|
||||
} else if (counterOverhead + weight >= gc_.GetThreshold() && konan::getTimeMicros() - timeOfLastGcUs_ >= gc_.GetCooldownThresholdUs()) {
|
||||
timeOfLastGcUs_ = konan::getTimeMicros();
|
||||
safePointsCounter_ = 0;
|
||||
PerformFullGC();
|
||||
}
|
||||
@@ -114,6 +115,7 @@ gc::SameThreadMarkAndSweep::SameThreadMarkAndSweep() noexcept {
|
||||
// TODO: Make it even more aggressive and run on a subset of backend.native tests.
|
||||
threshold_ = 1000;
|
||||
allocationThresholdBytes_ = 10000;
|
||||
cooldownThresholdUs_ = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -61,6 +61,7 @@ public:
|
||||
mm::ThreadData& threadData_;
|
||||
size_t allocatedBytes_ = 0;
|
||||
size_t safePointsCounter_ = 0;
|
||||
uint64_t timeOfLastGcUs_ = konan::getTimeMicros();
|
||||
};
|
||||
|
||||
SameThreadMarkAndSweep() noexcept;
|
||||
@@ -72,6 +73,9 @@ public:
|
||||
void SetAllocationThresholdBytes(size_t value) noexcept { allocationThresholdBytes_ = value; }
|
||||
size_t GetAllocationThresholdBytes() noexcept { return allocationThresholdBytes_; }
|
||||
|
||||
void SetCooldownThresholdUs(uint64_t value) noexcept { cooldownThresholdUs_ = value; }
|
||||
uint64_t GetCooldownThresholdUs() noexcept { return cooldownThresholdUs_; }
|
||||
|
||||
void SetAutoTune(bool value) noexcept { autoTune_ = value; }
|
||||
bool GetAutoTune() noexcept { return autoTune_; }
|
||||
|
||||
@@ -80,6 +84,7 @@ private:
|
||||
|
||||
size_t threshold_ = 100000; // Roughly 1 safepoint per 10ms (on a subset of examples on one particular machine).
|
||||
size_t allocationThresholdBytes_ = 10 * 1024 * 1024; // 10MiB by default.
|
||||
uint64_t cooldownThresholdUs_ = 200 * 1000; // 200 milliseconds by default.
|
||||
bool autoTune_ = false;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user