Re: RFR: 8333086: Using Console.println is unnecessarily slow due to JLine initalization [v3]
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]
> 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&pr=19479&range=02 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=19479&range=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