Message-ID: From: "vlsi (@vlsi)" To: "pgjdbc/pgjdbc" Date: Mon, 20 Nov 2023 19:01:40 +0000 Subject: Re: [pgjdbc/pgjdbc] issue #2963: BufferedOutputStream in PGStream should be replaced to something more efficient In-Reply-To: References: List-Id: X-GitHub-Author-Login: vlsi X-GitHub-Comment-Id: 1819637495 X-GitHub-Comment-Type: issue_comment X-GitHub-Issue: 2963 X-GitHub-Repo: pgjdbc/pgjdbc X-GitHub-Type: comment X-GitHub-Url: https://github.com/pgjdbc/pgjdbc/issues/2963#issuecomment-1819637495 Content-Type: text/plain; charset=utf-8 > I think biggest optimization would be to replace FilterOutputStream with custom delegate. FilterOutputStream writes to given OutputStream one byte at a time I think `BuferredOutputStrem` overrides `write(byte[], int, int)` method, so your analysis does not sound quite right: https://github.com/openjdk/jdk/blob/30d895383eda37ba1475825a258feb0a15da1526/src/java.base/share/classes/java/io/BufferedOutputStream.java#L196-L209 In other words the flame graph looks like `PGStream.sendInteger2` calling `pgOutput.write(byte[])`. `pgOutput.write` happens to be a subclass of `FilterOutputSteram`, however, `FilterOutputStream.write(byte[])` calls `write(b, 0, b.length)` which turns out to be `BufferedOutputStream`. In other words, the flame graph suggests that in your case `PGStream.out` was `BufferedOutputStream`. I suggest we reproduce the issue with JMH first and then attempt to fix it.