You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2024/07/08 09:07:11 UTC
(lucene) 03/03: Override single byte writes to OutputStreamIndexOutput to remove locking (#13543)
This is an automated email from the ASF dual-hosted git repository.
jpountz pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/lucene.git
commit 35de1ead82d1344d660ea6a148b788e39c4a1d5a
Author: Armin Braun <me...@obrown.io>
AuthorDate: Mon Jul 8 10:59:50 2024 +0200
Override single byte writes to OutputStreamIndexOutput to remove locking (#13543)
Single byte writes to BufferedOutputStream show up pretty hot in
indexing benchmarks. We can save the locking overhead introduced by
JEP374 by overriding and providing a no-lock fastpath.
---
.../org/apache/lucene/store/OutputStreamIndexOutput.java | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/lucene/core/src/java/org/apache/lucene/store/OutputStreamIndexOutput.java b/lucene/core/src/java/org/apache/lucene/store/OutputStreamIndexOutput.java
index 5c3b4dbd88a..14b56a67e8a 100644
--- a/lucene/core/src/java/org/apache/lucene/store/OutputStreamIndexOutput.java
+++ b/lucene/core/src/java/org/apache/lucene/store/OutputStreamIndexOutput.java
@@ -135,5 +135,19 @@ public class OutputStreamIndexOutput extends IndexOutput {
BitUtil.VH_LE_LONG.set(buf, count, i);
count += Long.BYTES;
}
+
+ @Override
+ public void write(int b) throws IOException {
+ // override single byte write to avoid synchronization overhead now that JEP374 removed biased
+ // locking
+ byte[] buffer = buf;
+ int count = this.count;
+ if (count >= buffer.length) {
+ super.write(b);
+ } else {
+ buffer[count] = (byte) b;
+ this.count = count + 1;
+ }
+ }
}
}