Re: RFR: 8333086: Using Console.println is unnecessarily slow due to JLine initalization [v3]

2024-06-05 Thread Naoto Sato
On Wed, 5 Jun 2024 12:36:33 GMT, Jan Lahoda  wrote:

>> Consider these two programs:
>> 
>> 
>> public class SystemPrint {
>> public static void main(String... args) {
>> System.err.println("Hello!");
>> }
>> }
>> 
>> and:
>> 
>> public class IOPrint {
>> public static void main(String... args) {
>> java.io.IO.println("Hello!");
>> }
>> }
>> 
>> 
>> They do the same conceptual thing - write a text to the output. But, 
>> `IO.println` delegates to `Console.println`, which then delegates to a 
>> `Console` backend, and the default backend is currently based on JLine.
>> 
>> The issues is that JLine takes a quite a long time to initialize, and in a 
>> program like this, JLine is not really needed - it is used to provide better 
>> editing experience when reading input, but there's no reading in these 
>> programs.
>> 
>> For example, on my computer:
>> 
>> $ time java -classpath /tmp SystemPrint 
>> Hello!
>> 
>> real0m0,035s
>> user0m0,019s
>> sys 0m0,019s
>> 
>> $ time java -classpath /tmp --enable-preview IOPrint 
>> Hello!
>> 
>> real0m0,165s
>> user0m0,324s
>> sys 0m0,042s
>> 
>> 
>> The proposal herein is to delegate to the simpler `Console` backend from 
>> `java.base` as long as the user only uses methods that print to output, and 
>> switch to the JLine delegate when other methods (typically input) is used. 
>> Note that while technically `writer()` is a method doing output, it will 
>> force JLine initialization to avoid possible problems if the client caches 
>> the writer and uses it after switching the delegates.
>> 
>> With this patch, I can get timing like this:
>> 
>> $ time java --enable-preview -classpath /tmp/ IOPrint 
>> Hello!
>> 
>> real0m0,051s
>> user0m0,038s
>> sys 0m0,020s
>> 
>> 
>> which seems much more acceptable.
>> 
>> There is also #19467, which may reduce the time further.
>> 
>> A future work might focus on making JLine initialize faster, but avoiding 
>> JLine initialization in case where we don't need it seems like a good step 
>> to me in any case.
>
> Jan Lahoda has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   Correctly reflecting review feedback

LGTM. Thanks for the changes.

-

Marked as reviewed by naoto (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/19479#pullrequestreview-2099801902


Re: RFR: 8333086: Using Console.println is unnecessarily slow due to JLine initalization [v3]

2024-06-05 Thread Jan Lahoda
> Consider these two programs:
> 
> 
> public class SystemPrint {
> public static void main(String... args) {
> System.err.println("Hello!");
> }
> }
> 
> and:
> 
> public class IOPrint {
> public static void main(String... args) {
> java.io.IO.println("Hello!");
> }
> }
> 
> 
> They do the same conceptual thing - write a text to the output. But, 
> `IO.println` delegates to `Console.println`, which then delegates to a 
> `Console` backend, and the default backend is currently based on JLine.
> 
> The issues is that JLine takes a quite a long time to initialize, and in a 
> program like this, JLine is not really needed - it is used to provide better 
> editing experience when reading input, but there's no reading in these 
> programs.
> 
> For example, on my computer:
> 
> $ time java -classpath /tmp SystemPrint 
> Hello!
> 
> real0m0,035s
> user0m0,019s
> sys 0m0,019s
> 
> $ time java -classpath /tmp --enable-preview IOPrint 
> Hello!
> 
> real0m0,165s
> user0m0,324s
> sys 0m0,042s
> 
> 
> The proposal herein is to delegate to the simpler `Console` backend from 
> `java.base` as long as the user only uses methods that print to output, and 
> switch to the JLine delegate when other methods (typically input) is used. 
> Note that while technically `writer()` is a method doing output, it will 
> force JLine initialization to avoid possible problems if the client caches 
> the writer and uses it after switching the delegates.
> 
> With this patch, I can get timing like this:
> 
> $ time java --enable-preview -classpath /tmp/ IOPrint 
> Hello!
> 
> real0m0,051s
> user0m0,038s
> sys 0m0,020s
> 
> 
> which seems much more acceptable.
> 
> There is also #19467, which may reduce the time further.
> 
> A future work might focus on making JLine initialize faster, but avoiding 
> JLine initialization in case where we don't need it seems like a good step to 
> me in any case.

Jan Lahoda has updated the pull request incrementally with one additional 
commit since the last revision:

  Correctly reflecting review feedback

-

Changes:
  - all: https://git.openjdk.org/jdk/pull/19479/files
  - new: https://git.openjdk.org/jdk/pull/19479/files/7a0c448f..f3259793

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk=19479=02
 - incr: https://webrevs.openjdk.org/?repo=jdk=19479=01-02

  Stats: 2 lines in 1 file changed: 1 ins; 0 del; 1 mod
  Patch: https://git.openjdk.org/jdk/pull/19479.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/19479/head:pull/19479

PR: https://git.openjdk.org/jdk/pull/19479


Re: RFR: 8333086: Using Console.println is unnecessarily slow due to JLine initalization [v2]

2024-06-05 Thread Jan Lahoda
> Consider these two programs:
> 
> 
> public class SystemPrint {
> public static void main(String... args) {
> System.err.println("Hello!");
> }
> }
> 
> and:
> 
> public class IOPrint {
> public static void main(String... args) {
> java.io.IO.println("Hello!");
> }
> }
> 
> 
> They do the same conceptual thing - write a text to the output. But, 
> `IO.println` delegates to `Console.println`, which then delegates to a 
> `Console` backend, and the default backend is currently based on JLine.
> 
> The issues is that JLine takes a quite a long time to initialize, and in a 
> program like this, JLine is not really needed - it is used to provide better 
> editing experience when reading input, but there's no reading in these 
> programs.
> 
> For example, on my computer:
> 
> $ time java -classpath /tmp SystemPrint 
> Hello!
> 
> real0m0,035s
> user0m0,019s
> sys 0m0,019s
> 
> $ time java -classpath /tmp --enable-preview IOPrint 
> Hello!
> 
> real0m0,165s
> user0m0,324s
> sys 0m0,042s
> 
> 
> The proposal herein is to delegate to the simpler `Console` backend from 
> `java.base` as long as the user only uses methods that print to output, and 
> switch to the JLine delegate when other methods (typically input) is used. 
> Note that while technically `writer()` is a method doing output, it will 
> force JLine initialization to avoid possible problems if the client caches 
> the writer and uses it after switching the delegates.
> 
> With this patch, I can get timing like this:
> 
> $ time java --enable-preview -classpath /tmp/ IOPrint 
> Hello!
> 
> real0m0,051s
> user0m0,038s
> sys 0m0,020s
> 
> 
> which seems much more acceptable.
> 
> There is also #19467, which may reduce the time further.
> 
> A future work might focus on making JLine initialize faster, but avoiding 
> JLine initialization in case where we don't need it seems like a good step to 
> me in any case.

Jan Lahoda has updated the pull request incrementally with one additional 
commit since the last revision:

  Reflecting review feedback - explicitly selecting the jdk.internal.le 
provider in the test.

-

Changes:
  - all: https://git.openjdk.org/jdk/pull/19479/files
  - new: https://git.openjdk.org/jdk/pull/19479/files/9886732e..7a0c448f

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk=19479=01
 - incr: https://webrevs.openjdk.org/?repo=jdk=19479=00-01

  Stats: 1 line in 1 file changed: 0 ins; 0 del; 1 mod
  Patch: https://git.openjdk.org/jdk/pull/19479.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/19479/head:pull/19479

PR: https://git.openjdk.org/jdk/pull/19479


Re: RFR: 8333086: Using Console.println is unnecessarily slow due to JLine initalization

2024-06-04 Thread Naoto Sato
On Thu, 30 May 2024 13:50:33 GMT, Jan Lahoda  wrote:

> Consider these two programs:
> 
> 
> public class SystemPrint {
> public static void main(String... args) {
> System.err.println("Hello!");
> }
> }
> 
> and:
> 
> public class IOPrint {
> public static void main(String... args) {
> java.io.IO.println("Hello!");
> }
> }
> 
> 
> They do the same conceptual thing - write a text to the output. But, 
> `IO.println` delegates to `Console.println`, which then delegates to a 
> `Console` backend, and the default backend is currently based on JLine.
> 
> The issues is that JLine takes a quite a long time to initialize, and in a 
> program like this, JLine is not really needed - it is used to provide better 
> editing experience when reading input, but there's no reading in these 
> programs.
> 
> For example, on my computer:
> 
> $ time java -classpath /tmp SystemPrint 
> Hello!
> 
> real0m0,035s
> user0m0,019s
> sys 0m0,019s
> 
> $ time java -classpath /tmp --enable-preview IOPrint 
> Hello!
> 
> real0m0,165s
> user0m0,324s
> sys 0m0,042s
> 
> 
> The proposal herein is to delegate to the simpler `Console` backend from 
> `java.base` as long as the user only uses methods that print to output, and 
> switch to the JLine delegate when other methods (typically input) is used. 
> Note that while technically `writer()` is a method doing output, it will 
> force JLine initialization to avoid possible problems if the client caches 
> the writer and uses it after switching the delegates.
> 
> With this patch, I can get timing like this:
> 
> $ time java --enable-preview -classpath /tmp/ IOPrint 
> Hello!
> 
> real0m0,051s
> user0m0,038s
> sys 0m0,020s
> 
> 
> which seems much more acceptable.
> 
> There is also #19467, which may reduce the time further.
> 
> A future work might focus on making JLine initialize faster, but avoiding 
> JLine initialization in case where we don't need it seems like a good step to 
> me in any case.

Looks good with a minor nit.

test/jdk/jdk/internal/jline/LazyJdkConsoleProvider.java line 74:

> 72: ProcessBuilder builder =
> 73: 
> ProcessTools.createTestJavaProcessBuilder("--enable-preview",
> 74:   
> "-verbose:class",

Better to explicitly specify `-Djdk.console=jdk.internal.le`

-

PR Review: https://git.openjdk.org/jdk/pull/19479#pullrequestreview-2096855434
PR Review Comment: https://git.openjdk.org/jdk/pull/19479#discussion_r1626281874


Re: RFR: 8333086: Using Console.println is unnecessarily slow due to JLine initalization

2024-06-04 Thread Adam Sotona
On Thu, 30 May 2024 13:50:33 GMT, Jan Lahoda  wrote:

> Consider these two programs:
> 
> 
> public class SystemPrint {
> public static void main(String... args) {
> System.err.println("Hello!");
> }
> }
> 
> and:
> 
> public class IOPrint {
> public static void main(String... args) {
> java.io.IO.println("Hello!");
> }
> }
> 
> 
> They do the same conceptual thing - write a text to the output. But, 
> `IO.println` delegates to `Console.println`, which then delegates to a 
> `Console` backend, and the default backend is currently based on JLine.
> 
> The issues is that JLine takes a quite a long time to initialize, and in a 
> program like this, JLine is not really needed - it is used to provide better 
> editing experience when reading input, but there's no reading in these 
> programs.
> 
> For example, on my computer:
> 
> $ time java -classpath /tmp SystemPrint 
> Hello!
> 
> real0m0,035s
> user0m0,019s
> sys 0m0,019s
> 
> $ time java -classpath /tmp --enable-preview IOPrint 
> Hello!
> 
> real0m0,165s
> user0m0,324s
> sys 0m0,042s
> 
> 
> The proposal herein is to delegate to the simpler `Console` backend from 
> `java.base` as long as the user only uses methods that print to output, and 
> switch to the JLine delegate when other methods (typically input) is used. 
> Note that while technically `writer()` is a method doing output, it will 
> force JLine initialization to avoid possible problems if the client caches 
> the writer and uses it after switching the delegates.
> 
> With this patch, I can get timing like this:
> 
> $ time java --enable-preview -classpath /tmp/ IOPrint 
> Hello!
> 
> real0m0,051s
> user0m0,038s
> sys 0m0,020s
> 
> 
> which seems much more acceptable.
> 
> There is also #19467, which may reduce the time further.
> 
> A future work might focus on making JLine initialize faster, but avoiding 
> JLine initialization in case where we don't need it seems like a good step to 
> me in any case.

It looks like a legit performance trick.

-

Marked as reviewed by asotona (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/19479#pullrequestreview-2096720909


RFR: 8333086: Using Console.println is unnecessarily slow due to JLine initalization

2024-05-30 Thread Jan Lahoda
Consider these two programs:


public class SystemPrint {
public static void main(String... args) {
System.err.println("Hello!");
}
}

and:

public class IOPrint {
public static void main(String... args) {
java.io.IO.println("Hello!");
}
}


They do the same conceptual thing - write a text to the output. But, 
`IO.println` delegates to `Console.println`, which then delegates to a 
`Console` backend, and the default backend is currently based on JLine.

The issues is that JLine takes a quite a long time to initialize, and in a 
program like this, JLine is not really needed - it is used to provide better 
editing experience when reading input, but there's no reading in these programs.

For example, on my computer:

$ time java -classpath /tmp SystemPrint 
Hello!

real0m0,035s
user0m0,019s
sys 0m0,019s

$ time java -classpath /tmp --enable-preview IOPrint 
Hello!

real0m0,165s
user0m0,324s
sys 0m0,042s


The proposal herein is to delegate to the simpler `Console` backend from 
`java.base` as long as the user only uses methods that print to output, and 
switch to the JLine delegate when other methods (typically input) is used. Note 
that while technically `writer()` is a method doing output, it will force JLine 
initialization to avoid possible problems if the client caches the writer and 
uses it after switching the delegates.

With this patch, I can get timing like this:

$ time java --enable-preview -classpath /tmp/ IOPrint 
Hello!

real0m0,051s
user0m0,038s
sys 0m0,020s


which seems much more acceptable.

There is also #19467, which may reduce the time further.

A future work might focus on making JLine initialize faster, but avoiding JLine 
initialization in case where we don't need it seems like a good step to me in 
any case.

-

Commit messages:
 - Cleanup, addint test.
 - Using println correctly, flushing the java.base delegate before switching to 
JLine.
 - Force Terminal when writer is requested.
 - Attempting to speedup start by delaying initialization of JLine until really 
necessary.

Changes: https://git.openjdk.org/jdk/pull/19479/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk=19479=00
  Issue: https://bugs.openjdk.org/browse/JDK-8333086
  Stats: 225 lines in 2 files changed: 212 ins; 1 del; 12 mod
  Patch: https://git.openjdk.org/jdk/pull/19479.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/19479/head:pull/19479

PR: https://git.openjdk.org/jdk/pull/19479