Re: RFR: 8358533: Improve performance of java.io.Reader.readAllLines

2025-06-24 Thread Andrey Turbanov
On Wed, 18 Jun 2025 00:04:37 GMT, Brian Burkhalter wrote: > Replaces the implementation `readAllCharsAsString().lines().toList()` with > reading into a temporary `char` array which is then processed to detect line > terminators and copy non-terminating characters into strings which are added >

Re: RFR: 8358533: Improve performance of java.io.Reader.readAllLines

2025-06-23 Thread Stuart Marks
On Thu, 19 Jun 2025 11:08:32 GMT, Markus KARG wrote: >> Replaces the implementation `readAllCharsAsString().lines().toList()` with >> reading into a temporary `char` array which is then processed to detect line >> terminators and copy non-terminating characters into strings which are added >>

Re: RFR: 8358533: Improve performance of java.io.Reader.readAllLines

2025-06-23 Thread Stuart Marks
On Thu, 19 Jun 2025 10:57:52 GMT, Markus KARG wrote: >>> I think we should treat "\r\n" as a single line terminator? >> >> You are correct: that needs to be fixed: >> >> jshell> Reader r = new StringReader("hello\r\nworld") >> r ==> java.io.StringReader@480bdb19 >> >> jshell> r.readAllLines()

Re: RFR: 8358533: Improve performance of java.io.Reader.readAllLines

2025-06-20 Thread Xueming Shen
On Fri, 20 Jun 2025 15:52:08 GMT, Roger Riggs wrote: >> My suggestion is to call `new StringBuilder(0)` as it is possible this is >> completely unused because we always hit the `eol && sb.length() == 0` path >> below. > > The change is motivated by performance, but there will be many inputs tha

Re: RFR: 8358533: Improve performance of java.io.Reader.readAllLines

2025-06-20 Thread Chen Liang
On Thu, 19 Jun 2025 10:53:14 GMT, Markus KARG wrote: >>> Is there a reason for this pre-allocation? >> >> What would you suggest? Start with a smaller allocation and increase it if >> needed? There is no possibility of knowing the length of the stream. > > As this PR explicitly targets performa

Re: RFR: 8358533: Improve performance of java.io.Reader.readAllLines

2025-06-20 Thread Roger Riggs
On Fri, 20 Jun 2025 15:50:53 GMT, Chen Liang wrote: >> As this PR explicitly targets performance and as the aim of this method is >> to keep **all** content in-memory anyways, I wonder if it would be >> acceptable and even faster to pre-allocate `new >> StringBuilder(TRANSFER_BUFFER_SIZE)`? In

Re: RFR: 8358533: Improve performance of java.io.Reader.readAllLines

2025-06-19 Thread Markus KARG
On Wed, 18 Jun 2025 00:04:37 GMT, Brian Burkhalter wrote: > Replaces the implementation `readAllCharsAsString().lines().toList()` with > reading into a temporary `char` array which is then processed to detect line > terminators and copy non-terminating characters into strings which are added >

Re: RFR: 8358533: Improve performance of java.io.Reader.readAllLines

2025-06-19 Thread Markus KARG
On Wed, 18 Jun 2025 16:57:22 GMT, Brian Burkhalter wrote: >> src/java.base/share/classes/java/io/Reader.java line 455: >> >>> 453: List lines = new ArrayList(); >>> 454: >>> 455: StringBuilder sb = new StringBuilder(82); >> >> Is there a reason for this pre-allocation? If the w

Re: RFR: 8358533: Improve performance of java.io.Reader.readAllLines

2025-06-19 Thread Markus KARG
On Wed, 18 Jun 2025 16:45:33 GMT, Brian Burkhalter wrote: >> I think we should treat "\r\n" as a single line terminator? for example >> >> "hello\r\nworld".lines().forEach(line -> out.format("[%s]\n", line)); >> => >> [hello] >> [world] >> >> instead of (the current impl) >> >> [hello] >> []

Re: RFR: 8358533: Improve performance of java.io.Reader.readAllLines

2025-06-18 Thread Brian Burkhalter
On Wed, 18 Jun 2025 02:26:48 GMT, Chen Liang wrote: > Is there a reason for this pre-allocation? What would you suggest? Start with a smaller allocation and increase it if needed? There is no possibility of knowing the length of the stream. - PR Review Comment: https://git.openjdk

Re: RFR: 8358533: Improve performance of java.io.Reader.readAllLines

2025-06-18 Thread Brian Burkhalter
On Wed, 18 Jun 2025 02:38:04 GMT, Chen Liang wrote: > Edit: No, we need to check empty lines. Right. I caught this during testing. - PR Review Comment: https://git.openjdk.org/jdk/pull/25863#discussion_r2155088265

Re: RFR: 8358533: Improve performance of java.io.Reader.readAllLines

2025-06-18 Thread Brian Burkhalter
On Wed, 18 Jun 2025 02:33:40 GMT, Xueming Shen wrote: > I think we should treat "\r\n" as a single line terminator? You are correct: that needs to be fixed: jshell> Reader r = new StringReader("hello\r\nworld") r ==> java.io.StringReader@480bdb19 jshell> r.readAllLines() $3 ==> [hello, , world

Re: RFR: 8358533: Improve performance of java.io.Reader.readAllLines

2025-06-18 Thread Brian Burkhalter
On Wed, 18 Jun 2025 09:20:12 GMT, Shaojin Wen wrote: > If we want better performance, we should go a step further and overload the > readAllLines method in the Reader implementation class. Perhaps, but not in this request. A separate issue should be filed and addressed subsequently. -

Re: RFR: 8358533: Improve performance of java.io.Reader.readAllLines

2025-06-18 Thread Shaojin Wen
On Wed, 18 Jun 2025 00:04:37 GMT, Brian Burkhalter wrote: > Replaces the implementation `readAllCharsAsString().lines().toList()` with > reading into a temporary `char` array which is then processed to detect line > terminators and copy non-terminating characters into strings which are added >

Re: RFR: 8358533: Improve performance of java.io.Reader.readAllLines

2025-06-17 Thread Chen Liang
On Wed, 18 Jun 2025 00:04:37 GMT, Brian Burkhalter wrote: > Replaces the implementation `readAllCharsAsString().lines().toList()` with > reading into a temporary `char` array which is then processed to detect line > terminators and copy non-terminating characters into strings which are added >

Re: RFR: 8358533: Improve performance of java.io.Reader.readAllLines

2025-06-17 Thread Xueming Shen
On Wed, 18 Jun 2025 01:34:14 GMT, Brian Burkhalter wrote: >> src/java.base/share/classes/java/io/Reader.java line 469: >> >>> 467: if (c == '\r' || c == '\n') >>> 468: break; >>> 469: term++; >> >> It might be worth adding a test o

Re: RFR: 8358533: Improve performance of java.io.Reader.readAllLines

2025-06-17 Thread Shaojin Wen
On Wed, 18 Jun 2025 00:04:37 GMT, Brian Burkhalter wrote: > Replaces the implementation `readAllCharsAsString().lines().toList()` with > reading into a temporary `char` array which is then processed to detect line > terminators and copy non-terminating characters into strings which are added >

Re: RFR: 8358533: Improve performance of java.io.Reader.readAllLines

2025-06-17 Thread Shaojin Wen
On Wed, 18 Jun 2025 00:04:37 GMT, Brian Burkhalter wrote: > Replaces the implementation `readAllCharsAsString().lines().toList()` with > reading into a temporary `char` array which is then processed to detect line > terminators and copy non-terminating characters into strings which are added >

Re: RFR: 8358533: Improve performance of java.io.Reader.readAllLines

2025-06-17 Thread Brian Burkhalter
On Wed, 18 Jun 2025 00:53:51 GMT, Roger Riggs wrote: >> Replaces the implementation `readAllCharsAsString().lines().toList()` with >> reading into a temporary `char` array which is then processed to detect line >> terminators and copy non-terminating characters into strings which are added >>

Re: RFR: 8358533: Improve performance of java.io.Reader.readAllLines

2025-06-17 Thread Roger Riggs
On Wed, 18 Jun 2025 00:04:37 GMT, Brian Burkhalter wrote: > Replaces the implementation `readAllCharsAsString().lines().toList()` with > reading into a temporary `char` array which is then processed to detect line > terminators and copy non-terminating characters into strings which are added >

Re: RFR: 8358533: Improve performance of java.io.Reader.readAllLines

2025-06-17 Thread Brian Burkhalter
On Wed, 18 Jun 2025 00:04:37 GMT, Brian Burkhalter wrote: > Replaces the implementation `readAllCharsAsString().lines().toList()` with > reading into a temporary `char` array which is then processed to detect line > terminators and copy non-terminating characters into strings which are added >