git » sdk » commit 032752b

enableConstrainedMemoryMode

author Stephen Paul Weber
2025-06-24 17:59:49 UTC
committer Stephen Paul Weber
2025-06-24 17:59:49 UTC
parent 2eb86df366f6a67d5af9f0f08d1ee02cad5f465d

enableConstrainedMemoryMode

For at least iOS NSE we want to tell the GC to keep less headroom to
stay away from that 24MB limit.

snikket/Config.hx +23 -0

diff --git a/snikket/Config.hx b/snikket/Config.hx
index 69c5fca..c3a4e17 100644
--- a/snikket/Config.hx
+++ b/snikket/Config.hx
@@ -1,6 +1,15 @@
 package snikket;
 
+#if cpp
+import HaxeCBridge;
+import cpp.NativeGc;
+#end
+
 @:expose
+#if cpp
+@:build(HaxeCBridge.expose())
+@:build(HaxeSwiftBridge.expose())
+#end
 class Config {
 	/**
 		Produce /.well-known/ni/ paths instead of ni:/// URIs
@@ -9,4 +18,18 @@ class Config {
 		This can be useful eg for intercepting with a Service Worker.
 	**/
 	public static var relativeHashUri = false;
+
+	@:allow(snikket)
+	private static var constrainedMemoryMode = false;
+
+	#if cpp
+	/**
+		Trades off some performance for lower / more consistent memory usage
+	**/
+	public static function enableConstrainedMemoryMode() {
+		NativeGc.setMinimumFreeSpace(500000);
+		NativeGc.setTargetFreeSpacePercentage(5);
+		constrainedMemoryMode = true;
+	}
+	#end
 }