RFR: 8255729: com.sun.tools.javac.processing.JavacFiler.FilerOutputStream is inefficient

Joel Borggrén-Franck jfranck at openjdk.java.net
Mon Dec 21 09:37:55 UTC 2020


On Sun, 20 Dec 2020 17:29:59 GMT, Guoxiong Li <github.com+13688759+lgxbslgx at openjdk.org> wrote:

> Hi all,
> 
> `FilerOutputStream` extends `FilterOutputStream` without overwriting the method `write(byte b[], int off, int len)` which would suffer from the performance problem.
> This patch fixes it and adds some `@Override` to polish the code. But I can't find a good way to write a corresponding test case. Maybe it doesn't need a test case. And all existing tests in `test/langtools/tools/javac` passed locally.
> 
> Thank you for taking the time to review.
> 
> Best Regards.

I'd like to see some kind of evidence that performance was actually improved. I realise this might be hard to make a good standalone test for, but it should be doable as an experiment observing how many times write(int) is called for a huge file.

src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacFiler.java line 282:

> 280:             if ((off | len | (b.length - (len + off)) | (off + len)) < 0)
> 281:                 throw new IndexOutOfBoundsException();
> 282:             out.write(b, off, len);

If I understand this `out` is the underlying `OutputStream` and calling `write(byte[], int, int)` performs the same one-byte-at-a-time write as without the override.

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

PR: https://git.openjdk.java.net/jdk/pull/1854


More information about the compiler-dev mailing list