Hi All,
Apologies for the third post in a row. I wanted to highlight the speed increases I am getting on JavaScript and C++ and would like opinions as to why this might be the case.
I’ve uploaded the latest version of the code here (which now supports variable capture): https://lib.haxe.org/p/haxe-delegates/0.0.1/
Hxcpp:
This is without debugging:
src/Test.hx:17: *** Running without inlines ***
src/Test.hx:53: Haxe function type: 0.3874378
src/Test.hx:59: Delegate: 0.0279917
src/Test.hx:24: *** Running with inlines ***
src/Test.hx:53: Haxe function type: 0.3732177
src/Test.hx:59: Delegate: 0.0155093000000001
src/Test.hx:31: *** Running with anonymous functions ***
src/Test.hx:53: Haxe function type: 0.3604134
src/Test.hx:59: Delegate: 0.0193384999999999
In other words, the Delegate type executes 24 times faster and 14 times faster with and without inlines respectively.
JavaScript:
app.js:24 src/Test.hx:17: *** Running without inlines ***
app.js:60 src/Test.hx:53: Haxe function type: 0.008699999999254943
app.js:68 src/Test.hx:59: Delegate: 0.007800000000745058
app.js:30 src/Test.hx:24: *** Running with inlines ***
app.js:60 src/Test.hx:53: Haxe function type: 0.09140000000037253
app.js:68 src/Test.hx:59: Delegate: 0.012100000001490113
app.js:37 src/Test.hx:31: *** Running with anonymous functions ***
app.js:60 src/Test.hx:53: Haxe function type: 0.06580000000074504
app.js:68 src/Test.hx:59: Delegate: 0.014500000000000013
Here, the Delegate type executes in roughly the same time as a function type, but 8 times faster with inlines and 4 times faster with anonymous functions.
Some obvious limitations still exist:
- Oddly enough, anonymous functions break if we try to reference imported types that expect type parameters, and so need to be preceded by their package in order to work.
- Larger output size, and so balancing the cost of runtime execution and output size as expected from generics should be considered.
- Delegate types cannot be generated from functions or classes with type parameters.