From 0bb71e4fcc0eeb7687b84ee196ea84bd1e5061a4 Mon Sep 17 00:00:00 2001 From: Tom Gasson Date: Tue, 3 Sep 2024 12:52:25 +1000 Subject: [PATCH] Shortcut hash computation for constant rules This reduces the number of hashing operations performed substantially --- src/main/kotlin/com/statsig/sdk/Evaluator.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/com/statsig/sdk/Evaluator.kt b/src/main/kotlin/com/statsig/sdk/Evaluator.kt index bc28802..a95d6df 100644 --- a/src/main/kotlin/com/statsig/sdk/Evaluator.kt +++ b/src/main/kotlin/com/statsig/sdk/Evaluator.kt @@ -315,7 +315,11 @@ internal class Evaluator( return } - val pass = + val pass = if (rule.passPercentage == 0.0) { + false + } else if (rule.passPercentage == 100.0){ + true + } else { computeUserHash( config.salt + '.' + @@ -324,6 +328,7 @@ internal class Evaluator( (getUnitID(ctx.user, rule.idType) ?: Const.EMPTY_STR), ) .mod(10000UL) < (rule.passPercentage.times(100.0)).toULong() + } if (!pass) { ctx.evaluation.jsonValue = config.defaultValue