Skip to content

Add benchmark to compare notifying listeners stored in lists and arrays - #6

Merged
manoelcampos merged 1 commit into
masterfrom
listeners-notification-benchmark
Oct 20, 2026
Merged

manoelcampos merged 1 commit into
masterfrom
listeners-notification-benchmark

Conversation

@manoelcampos

Copy link
Copy Markdown
Contributor

Related to cloudsimplus/cloudsimplus#586 (PR cloudsimplus/cloudsimplus#593)

Summary

Adds ListenersNotificationBenchmark (new org.cloudsimplus.listeners package) to check if storing listeners in plain arrays, instead of the immutable lists created by the Listeners class, makes notification faster.

A for-each loop over a List calls iterator(), which creates an object, unless the JIT removes it with escape analysis. A for-each loop over an array creates no object. The benchmark should be run with -prof gc to see if the iterator is created (gc.alloc.rate.norm).

  • The listeners just increment a counter and all get the same EventInfo, so only the iteration is measured.
  • single*: notifies one list (or array) with 0 to 3 listeners. Each param value runs in its own fork, so the loop only sees one List class.
  • mixed*: notifies lists with 0 to 3 listeners in each operation, like a simulation with many VMs that have different numbers of listeners. This way, the loop sees both List12 and ListN, as in a real simulation.

Results

java -jar target/cloudsimplus-benchmarks-9.0.0-SNAPSHOT-uber.jar ListenersNotificationBenchmark -f 1 -wi 3 -w 1s -i 5 -r 1s -prof gc (JDK 25)

Benchmark Listeners List (ns/op) Array (ns/op) List alloc (B/op) Array alloc (B/op)
single 0 0.86 0.65 0 0
single 1 2.30 2.30 0 0
single 2 4.51 4.60 0 0
single 3 6.76 6.78 0 0
mixed (sizes 0–3) — 23.2 13.9 128 0

When the loop sees only one list class, escape analysis removes the iterator, and lists and arrays perform the same.
When it sees both classes (the realistic case), an iterator is created for each list (32 B × 4 lists = 128 B/op), and the list version is ~67% slower.

🤖 Generated with Claude Code

Measures the time and memory to notify listeners stored in the immutable lists
created by the Listeners class (cloudsimplus/cloudsimplus#586) and in plain arrays.
Run with -prof gc to see if the for-each loop creates an iterator.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@manoelcampos manoelcampos self-assigned this Oct 20, 2026
@manoelcampos
manoelcampos merged commit 159c063 into master Oct 20, 2026
1 check failed
@manoelcampos
manoelcampos deleted the listeners-notification-benchmark branch October 20, 2026 20:37
manoelcampos added a commit that referenced this pull request Oct 20, 2026
…ys (PR #6 and #9)

Measures the time and memory to notify listeners stored in immutable lists
(as created by the Listeners class from cloudsimplus/cloudsimplus#586) and in plain arrays.
Run with -prof gc to see if the for-each loop creates an iterator.

The benchmark builds the lists itself with List.of(array), which gives the same
List classes CloudSim Plus uses, without depending on the Listeners class.
This way, it compiles against both CloudSim Plus 8.5.1 and 9.

Closes #8

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant