Hi all,
This patch proposes a new optimization to improve the performance of 
String.equals when one of the strings is constant, by inlining the comparisons 
into the IR directly. For small strings, this optimization is beneficial as the 
backend implementation of `StrEquals` can include a lot of generated code, 
including code to jump between vector and scalar loops based on the array 
length. When a small constant string (size <= 16) is passed to String.equals(), 
this optimization proposes reading the byte[] of the constant string at compile 
time and emitting a chain of If nodes comparing against those constants. This 
reduces the memory accesses needed by half, as we no longer load from the 
constant string's memory at runtime. These checks in the IR can read multiple 
bytes from the underlying byte[] at a time using larger typed loads, which 
greatly reduces the number of comparisons needed.

I've attached an IR test, as well as a JMH benchmark. Tier 1 testing passed on 
my Linux x64 machine, and I'll attach the results of the benchmark for x86 and 
aarch64 in a subsequent comment. Thoughts and reviews would be appreciated!

---------
- [x] I confirm that I make this contribution in accordance with the [OpenJDK 
Interim AI Policy](https://openjdk.org/legal/ai).

-------------

Commit messages:
 - Optimize constant string comparisons

Changes: https://git.openjdk.org/jdk/pull/33621/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=33621&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8395868
  Stats: 631 lines in 8 files changed: 587 ins; 39 del; 5 mod
  Patch: https://git.openjdk.org/jdk/pull/33621.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/33621/head:pull/33621

PR: https://git.openjdk.org/jdk/pull/33621

Reply via email to