Repository navigation
Conversation
… argument isn't boxed (not cppia) (HaxeFoundation#13249)
|
I would also be curious if this could fix some of the performance loss in haxe 5 seen in the benchmarks. The -0.0 boxing bug is incorrect behaviour (HaxeFoundation/hxcpp#1476), so I don't think it makes sense for the test to rely on it as a way to check whether boxing occurred.
Is there any way we could avoid the Dynamic for the callable in the non-dynamic/non-reflective case?
@Aidan63 might be able to mention if there were any reasons. |
Since the typed functions (HaxeFoundation#11151), every argument with a default was typed through cpp_type_of_null, so a Float or Int argument with a default became ::Dynamic, and each call boxed it, allocating. A method's argument with a constant default keeps its scalar type again, printed as ::hx::Null<T> and read with .Default, as before HaxeFoundation#11151. The method's function value (its _dyn and its callable type) still takes the argument as Dynamic, so a null passed through it, by a Dynamic call or Reflect.callMethod, still takes the default. A closure captures the body's copy of the argument, so an override's signature is the same whatever its body captures. Dynamic methods and defaults that aren't constants are unchanged.
c402b41 to
68fda17
Compare
|
Thanks. hxcpp#1476 makes the -0 checks pass with or without this change, so they're gone. In their place, Reviewing it again turned up a break in the first version: an override whose closure captured its argument kept On the callable: a direct call never goes through it, so the non-dynamic, non-reflective case already passes the number unboxed. You mentioned some regressions? Which benchmarks are you talking about? |
|
Thanks for adjusting it! It would be nice if we could avoid the large amounts of raw c++ code in the tests , but if that's not feasible and it's fine with others then we can go with it. I'll leave it up to @Aidan63 to comment on the direct call vs callable value situation as I don't have as good a grasp of the new callable system.
These are found on benchs.haxe.org, with the sources at https://github.com/HaxeBenchmarks/benchmark-runner. There was a slight performance regression in haxe 5 for some of them when the typed callables were implemented so I wonder if this boxing could be partially to blame. |
#11151 changed how the C++ target compiles a function argument that has a default value. A
Float,IntorBoolargument with a default used to compile to a number. Since #11151 it compiles to::Dynamic, so every call wraps the number in a heap object:With this change, a method's argument with a constant default is
::hx::Null<T>again, as before #11151, and a direct call passes the number unboxed. The method used as a value still takes the argument asDynamic, sonullthrough aDynamiccall orReflect.callMethodstill takes the default. Dynamic methods and defaults that aren't constants are unchanged.If #11151 boxed these arguments on purpose, I'd be glad to hear why.
The test is
tests/unit/src/unit/issues/Issue13249.hx.static_asserts check that the arguments aren't taken asDynamic: they fail to compile before the change and pass after. The rest checks the default taken fornull, through overrides, closures that capture the argument, and an interface.Checked on Linux x64 with hxcpp master, together with #13248: the C++ unit tests, the cppia unit tests (with and without
-jit), and the sys, threads, event loop and misc C++ tests. Not checked: Windows, macOS, other compilers.Written by an AI agent (Claude) working with me, and reviewed by a second agent.