From df841134295049001f130c784efae34b31d9d23f Mon Sep 17 00:00:00 2001 From: Blaz Snuderl Date: Thu, 23 Apr 2026 10:56:15 +0200 Subject: [PATCH] Skip tautological evaluators in MessageEvaluator.append MessageEvaluator.append previously stored every evaluator unconditionally, so FieldEvaluators for fields with no rules still ran on every validate() call: hasField check, ObjectValue allocation, ValueEvaluator.evaluate with a zero-length evaluator list, return empty. None of that can ever produce a violation, so iterating them is pure overhead. ValueEvaluator.append already filters on tautology(); this change mirrors that in MessageEvaluator to match protovalidate-go's AppendNested (internal/evaluator/message.go:67-77), which skips appends whose Tautology() is true. The effect scales with the fraction of no-rule fields in a message. On a 2-field message (1 ruled, 1 unruled), per-call validate() dropped from ~977 ns to ~908 ns (~7%). Messages with more unconstrained fields save proportionally more. --- src/main/java/build/buf/protovalidate/MessageEvaluator.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/build/buf/protovalidate/MessageEvaluator.java b/src/main/java/build/buf/protovalidate/MessageEvaluator.java index e7966473..150cae21 100644 --- a/src/main/java/build/buf/protovalidate/MessageEvaluator.java +++ b/src/main/java/build/buf/protovalidate/MessageEvaluator.java @@ -56,6 +56,9 @@ public List evaluate(Value val, boolean failFast) * @param eval The evaluator to append. */ void append(Evaluator eval) { + if (eval.tautology()) { + return; + } evaluators.add(eval); } }