Repository navigation
Description
The Int64-key hash runtime switches from specialized Int64 value storage to generic object storage on its second boxed Int64 insertion, even when every value is an Int64.
Reproduced on main at d734565 with Haxe 4.3.7, Windows x86-64, MSVC 19.44.35213, HXCPP_M64 and smart strings enabled. The tests use an isolated local haxelib repository pointing at this checkout.
A native-API probe inserts two Dynamic values created from Int64 values larger than 32 bits. After the first insertion, HashRoot::store is hashInt64. After the second, it is hashObject. Both values are still correct, so this is unnecessary storage conversion and boxing rather than a value-corruption report.
In src/hx/Hash.cpp, __int64_hash_set selects Int64HashInt64 for vtInt64 when creating a hash. Its existing-hash path initializes want to hashObject and handles vtInt, vtFloat and vtString, but has no vtInt64 case. A second Int64 therefore falls through to conversion. __int_hash_set handles this case, and __int64_hash_set_int64 also preserves specialized storage.
Keep the specialized Int64 store when another compatible Int64 arrives through the Dynamic setter. Cover promotion from an Int store, repeated Int64 values, and genuinely mixed values that do need object storage. This only needs a runtime change. The native entry points already exist; no Haxe compiler or standard library change is required.
A 100,000-entry local probe kept both maps live and collected three times before each heap measurement. The keys were 0 through 99,999 and values were Int64.make(1, i):
- A map populated through __int64_hash_set_int64 grew the live GC heap by 6,101,888 bytes.
- A second map populated through __int64_hash_set with boxed Int64 values added 8,498,176 bytes.
- The last values matched, and the Dynamic-setter map used hashObject.
That is about 39% more live heap in this run. These are GC heap-usage deltas, not exact allocation counts or a throughput benchmark. The avoidable full-store conversion also happens as soon as the second boxed value is inserted.
A conventional regression is prepared locally at test/regression/Int64HashDynamicValues, with Main.hx, build.hxml and stdout.txt. It checks specialization and value preservation. Haxe 4.3.7 has no Int64Map standard class, so this regression uses a small shim to call the existing native hash entry points and inspect their storage; it does not add a replacement standard library class.
Current output:
first value uses Int64 storage: true
second Int64 keeps specialized storage: false
values preserved: true
All three lines should be true. Main.hx:
@:buildXml('<files id="haxe"><compilerflag value="-I${HXCPP}/src"/></files>')
@:cppFileCode('#include <hx/Hash.h>')
class Main {
var h:Dynamic;
function new() {}
function set(key:haxe.Int64, value:Dynamic):Void {
untyped __global__.__int64_hash_set(__cpp__("HX_MAP_THIS"), key, value);
}
function get(key:haxe.Int64):haxe.Int64 {
return untyped __global__.__int64_hash_get_int64(h, key);
}
function usesInt64Storage():Bool {
return untyped __cpp__("static_cast<hx::HashRoot*>({0}.mPtr)->store == hx::hashInt64", h);
}
static function main() {
var map = new Main();
var first = haxe.Int64.make(1, 7);
var second = haxe.Int64.make(2, 9);
map.set(1, first);
Sys.println("first value uses Int64 storage: " + map.usesInt64Storage());
map.set(2, second);
Sys.println("second Int64 keeps specialized storage: " + map.usesInt64Storage());
Sys.println("values preserved: " + (map.get(1) == first && map.get(2) == second));
}
}
Build with haxe build.hxml -D HXCPP_M64 and run bin/Main from that directory after pointing haxelib at the checkout. The regression adds the runtime src directory to its include path to inspect HashRoot::store. Add a high-level Int64Map case when running against a Haxe version that supplies that class.
Activity
Keep Int64 value storage in Int64-keyed maps set through Dynamic