Performance of a continuation-based library generator

Pedro Lamarão pedro.lamarao at prodist.com.br
Thu Mar 23 16:35:48 UTC 2023


Hello all!
Thank you for your excellent work on project Loom!

I have been for some time experimenting with defining "generator" based
parsers in Java with Continuation. Recently, I moved on to performance
testing using JMH. Below are numbers for a custom text line parser from
this repository.

https://github.com/pedrolamarao/generators-jvm

In the below report:


   - "reader" measures BufferedReader.readLine
   - "parser" measures my algorithm packaged in a SAX like, callback based
   parser
   - "generator" measures my algorithm packaged in a generator based parser


Also, NewBenchmark measures just creating the parser, and NextBenchmark
measures running the parser on a 10240 lines in-memory string.

These are numbers for benchmarking on my intel core i7 notebook, windows 11
notebook.

# JMH version: 1.36
# VM version: JDK 20, OpenJDK 64-Bit Server VM, 20+36
# VM invoker:
C:\Users\Pedro\.gradle\jdks\azul_systems__inc_-20-amd64-windows\zulu20.28.85-ca-jdk20.0.0-win_x64\bin\java.exe
# VM options: --add-exports=java.base/jdk.internal.vm=ALL-UNNAMED
--enable-preview
# Blackhole mode: compiler (auto-detected, use
-Djmh.blackhole.autoDetect=false to disable)
# Warmup: 5 iterations, 10 s each
# Measurement: 5 iterations, 10 s each
# Timeout: 10 min per iteration
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Throughput, ops/time

Benchmark                      Mode  Cnt     Score    Error  Units
NewBenchmark.generator        thrpt   25  3967,583 ± 48,073  ops/s
NewBenchmark.generator:·jfr   thrpt            NaN             ---
NewBenchmark.parser           thrpt   25  3987,014 ± 20,057  ops/s
NewBenchmark.parser:·jfr      thrpt            NaN             ---
NewBenchmark.reader           thrpt   25  3968,044 ± 24,480  ops/s
NewBenchmark.reader:·jfr      thrpt            NaN             ---
NextBenchmark.generator       thrpt   25   562,381 ±  6,218  ops/s
NextBenchmark.generator:·jfr  thrpt            NaN             ---
NextBenchmark.parser          thrpt   25  1439,171 ± 36,915  ops/s
NextBenchmark.parser:·jfr     thrpt            NaN             ---
NextBenchmark.reader          thrpt   25  2826,489 ± 23,449  ops/s
NextBenchmark.reader:·jfr     thrpt            NaN             ---

It appears that creating continuations is very fast!

JFR says that NextLineBenchmark.generators spend a significant amount of
time inside Continuation.yield.

At this point, I'm not worried with the perfection of the line parser
algorithm, but with the viability of defining generator libraries using
Continuation.  I am no expert and fully expect there to be some critical
bug in my code, or in my understanding of how Continuation works. If
someone could give me a hint, I would be very grateful!

-- 
Pedro Lamarão
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/loom-dev/attachments/20230323/81ce48c3/attachment.htm>


More information about the loom-dev mailing list