You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"use strict";var__importDefault=(this&&this.__importDefault)||function(mod){return(mod&&mod.__esModule) ? mod : {"default": mod};};Object.defineProperty(exports,"__esModule",{value: true});consttypia_1=__importDefault(require("typia"));constX=(input=>{const$io0=input=>"object"===typeofinput.scale&&null!==input.scale&&("number"===typeofinput.scale.x&&"number"===typeofinput.scale.y&&"number"===typeofinput.scale.z)&&("object"===typeofinput.position&&null!==input.position&&("number"===typeofinput.position.x&&"number"===typeofinput.position.y&&"number"===typeofinput.position.z))&&("object"===typeofinput.rotate&&null!==input.rotate&&("number"===typeofinput.rotate.x&&"number"===typeofinput.rotate.y&&"number"===typeofinput.rotate.z))&&("object"===typeofinput.pivot&&null!==input.pivot&&("number"===typeofinput.pivot.x&&"number"===typeofinput.pivot.y&&"number"===typeofinput.pivot.z));const$io1=input=>"number"===typeofinput.x&&"number"===typeofinput.y&&"number"===typeofinput.z;// ^ $io1 function is defined in the validation HOT path, but never used.return"object"===typeofinput&&null!==input&&$io0(input);})({});
Performance
As per #513 (comment), 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 functionconstS=Date.now()for(leti=0;i<1_000_000_000;i++){constf=()=>{}// unusedconstx=typeof10==='number'}console.log(Date.now()-S)// 1166ms}{// without unused functionconstS=Date.now()for(leti=0;i<1_000_000_000;i++){constx=typeof10==='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!
The text was updated successfully, but these errors were encountered:
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 #513 (comment), 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!The text was updated successfully, but these errors were encountered: