From e23ea6b6793dcc2dea81f456e6d397c8e6828ed7 Mon Sep 17 00:00:00 2001 From: amcreynolds Date: Thu, 2 Nov 2017 15:46:16 -0700 Subject: [PATCH] Optimize StatusCode Line Matching for ASCII String.matches(String regex) results in a re-compilation of the regex every single invocation. Instead of using an underlying inefficient Pattern/Matcher, instead use String.startsWith(String prefix). This optimization matters for high throughput usecases when an endpoint goes down and the number of SERVER_ERROR spikes dramatically. --- src/main/java/net/spy/memcached/ops/StatusCode.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/spy/memcached/ops/StatusCode.java b/src/main/java/net/spy/memcached/ops/StatusCode.java index cbcb5d8e8..199fb224d 100644 --- a/src/main/java/net/spy/memcached/ops/StatusCode.java +++ b/src/main/java/net/spy/memcached/ops/StatusCode.java @@ -92,7 +92,8 @@ public static StatusCode fromAsciiLine(String line) { } else if (line.equals("NOT_FOUND")) { return ERR_NOT_FOUND; } else if (line.equals("ERROR") - || line.matches("^(CLIENT|SERVER)_ERROR.*")) { + || line.startsWith("CLIENT_ERROR") + || line.startsWith("SERVER_ERROR")) { return ERR_INTERNAL; } else { return ERR_CLIENT;