# Function types becoming dynamic after compilation

**URL:** <https://community.haxe.org/t/function-types-becoming-dynamic-after-compilation/3387>\
**Category:** Haxe\
**Tags:** haxe-cpp\
**Created:** [December 23, 2021, 9:35pm UTC](https://community.haxe.org/t/function-types-becoming-dynamic-after-compilation/3387 "2021-12-23T21:35:04Z")\
**Posts on this page:** 1\
**Showing post:** 21

<div class="post-metadata">

**Author:** ![thispolo](https://community.haxe.org/user_avatar/community.haxe.org/thispolo/32/1909_2.png) [@thispolo](https://community.haxe.org/u/thispolo)\
**Post date:** [August 29, 2022, 9:51am UTC](https://community.haxe.org/t/function-types-becoming-dynamic-after-compilation/3387/21 "2022-08-29T09:51:31Z")

</div>

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): [haxe-delegates (0.0.1)](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:

1. 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.
2. Larger output size, and so balancing the cost of runtime execution and output size as expected from generics should be considered.
3. Delegate types cannot be generated from functions or classes with type parameters.

---

_[View the full topic](https://community.haxe.org/t/function-types-becoming-dynamic-after-compilation/3387)._
