original-brownbear commented on code in PR #13543:
URL: https://github.com/apache/lucene/pull/13543#discussion_r1667797299
##########
lucene/core/src/java/org/apache/lucene/store/OutputStreamIndexOutput.java:
##########
@@ -135,5 +135,19 @@ void writeLong(long i) throws IOException {
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;
+ }
+ }
Review Comment:
I think this version is a bit faster (and maybe more than just a bit even
depending on the calling code) by avoiding the (most of the time unnecessary)
method call to `flushIfNeeded` (which itself does a bunch of field lookups).
For single-byte operations this matters somewhat I believe. It also saves
potentially unnecessary flush calls to the underlying stream, though those
might be irrelevant since we should only be hitting a single stream (from file
output stream) with a noop flush implementation here as far as I can tell.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]