mirror of https://github.com/apache/lucene.git
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.
This commit is contained in:
parent
675772546c
commit
9e04cb9c41
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue