From 851845579cc500f65ffb7aae50a773d2fb86af71 Mon Sep 17 00:00:00 2001 From: Simo Lin Date: Wed, 31 Dec 2025 15:29:37 -0800 Subject: [PATCH] perf(tree): optimize input_char_count calculation (#16238) --- sgl-model-gateway/src/policies/tree.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sgl-model-gateway/src/policies/tree.rs b/sgl-model-gateway/src/policies/tree.rs index 0ac002569..5a149ed87 100644 --- a/sgl-model-gateway/src/policies/tree.rs +++ b/sgl-model-gateway/src/policies/tree.rs @@ -554,7 +554,6 @@ impl Tree { } else { // Partial match - still use this node for tenant selection matched_chars += shared_count; - remaining = advance_by_chars(remaining, shared_count); prev = matched_node; break; } @@ -607,8 +606,10 @@ impl Tree { .insert(Arc::clone(&tenant), epoch); } - // Compute input char count from matched + remaining (deferred from start) - let input_char_count = matched_chars + remaining.chars().count(); + // Compute input char count directly from input text. + // This is equivalent to matched_chars + remaining.chars().count() but avoids + // needing to track remaining precisely through the traversal. + let input_char_count = text.chars().count(); PrefixMatchResult { tenant,