As per https://github.com/samchon/typia/issues/513#issuecomment-1437097704, I've followed up and run a few more performance tests on Typia comparing NaN and non-NaN assertions for JIT (which is how I've noticed this issue). The following is the results for the non-NaN checking case for TypeBox.
In theory, AOT should perform much faster than JIT here (and in pretty much all cases). In local testing I've run, I usually see around 10-20% performance degrade for using JIT. So in theory, Typia should be seeing upwards 20,000x (estimate)
Micro Benchmark
You can run the following script to test performance degradation for function definitions in hot code paths.
{ // with unused function
const S = Date.now()
for(let i = 0; i < 1_000_000_000; i++) {
const f = () => {} // unused
const x = typeof 10 === 'number'
}
console.log(Date.now() - S) // 1166ms
}
{ // without unused function
const S = Date.now()
for(let i = 0; i < 1_000_000_000; i++) {
const x = typeof 10 === 'number'
}
console.log(Date.now() - S) // 360ms
}
Notes
Comparing the validation routines for JIT / AOT, I don't see a lot of difference in terms of assertion logic. I think if you omit the unused $io1 function you're likely going to see an immediate performance boost. Also, you may get a bit more of a performance by inlining the $io0 function as a single conditional expression (this to avoid the function call / new stack frame).
In either case, it's probably going to be good to omit the unused function (if only to reduce JS output)
Anyway, Hope this helps
S
PS: Feel free to keep the AllowNaN = true in the TypeBox benchmarks!
Bug Report
Typia seems to be generating unused functions in validation code paths
Repro
Emit
Note the function
$io1
is emitted but never used.Performance
As per https://github.com/samchon/typia/issues/513#issuecomment-1437097704, I've followed up and run a few more performance tests on Typia comparing NaN and non-NaN assertions for JIT (which is how I've noticed this issue). The following is the results for the
non-NaN
checking case for TypeBox.In theory, AOT should perform much faster than JIT here (and in pretty much all cases). In local testing I've run, I usually see around 10-20% performance degrade for using JIT. So in theory, Typia should be seeing upwards 20,000x (estimate)
Micro Benchmark
You can run the following script to test performance degradation for function definitions in hot code paths.
Notes
Comparing the validation routines for JIT / AOT, I don't see a lot of difference in terms of assertion logic. I think if you omit the unused
$io1
function you're likely going to see an immediate performance boost. Also, you may get a bit more of a performance by inlining the$io0
function as a single conditional expression (this to avoid the function call / new stack frame).In either case, it's probably going to be good to omit the unused function (if only to reduce JS output) Anyway, Hope this helps S
PS: Feel free to keep the
AllowNaN = true
in the TypeBox benchmarks!