Closed deepak-nulu closed 3 years ago
The following benchmarks show that dispatching by enum is faster (higher throughput) than dispatching by class, and also more consistent between model elements that match the first and last checks:
benchmarks summary:
Benchmark Mode Cnt Score Error Units
treeWare.model.operator.DispatchBenchmarks.dispatchByClassFirst thrpt 2 467129735.883 ops/s
treeWare.model.operator.DispatchBenchmarks.dispatchByClassLast thrpt 2 5299428.140 ops/s
treeWare.model.operator.DispatchBenchmarks.dispatchByEnumFirst thrpt 2 706648973.610 ops/s
treeWare.model.operator.DispatchBenchmarks.dispatchByEnumLast thrpt 2 710008175.641 ops/s
The dispatch methods currently check class types using the following
when
expression:This translates to
if
checks in byte code; the decompiled code looks like the following:A lot of checks need to be performed if the class type is the last one being checked. Benchmarking shows the difference in throughput between dispatching model elements that match the first and last checks:
Throughput should be better and consistent if dispatching was performed by switching on enum values that indicate the type of the model elements.