New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[cpp] Array<Array<Float>> is Dynamic ? #4549
Comments
Every different type of array uses about 20k of exe size, so I use Array for all objects. |
Ok so there must be another problem, because the following code is wayyyy slower in hxcpp than in haxe/JS: class Bench
{
static public function main():Void
{
//read input
var array = new Array<Array<Float>>();
array = [
[3],
[7,4],
[2,4,6],
[8,5,9,3]
];
var sum = 0.0;
for ( i in 0...10000000 ){
sum += Solve(array);
}
trace(sum);
}
static private function Solve(t:Array<Array<Float>>):Float
{
for ( idxLine in (1...t.length) ){
for ( idxCol in (0...t[idxLine].length) ){
if ( idxCol == 0){
t[idxLine][idxCol] += t[idxLine-1][0];
} else if (idxCol == t[idxLine].length-1){
t[idxLine][idxCol] += t[idxLine-1][idxCol-1];
} else {
t[idxLine][idxCol] += Math.max(t[idxLine-1][idxCol-1], t[idxLine-1][idxCol]);
}
}
}
var maxi = -1.0;
for (elem in t[t.length-1]){
maxi = Math.max(maxi, elem);
}
return maxi;
}
} |
Yes I see - it is actually doing a dynamic_cast in this case. The reason for this is that I fundamentally can't trust the type of array data, eg:
Here, haxe says that make2DArray is returning an |
Is this still an issue? Running the benchmark I get comparable results between JS and C++. |
Personal conclusion:
|
2c...Be careful c# startup is slow because of the initial JIT phase but 2016-03-19 11:18 GMT+01:00 Simon Krajewski notifications@github.com:
David Elahee |
This is measured within |
C# without |
Well, even with |
Could you post the full benchmark code? |
It's just Nicolas' code with a Timer.measure around the loop: class Main
{
static public function main():Void
{
//read input
var array = new Array<Array<Float>>();
array = [
[3],
[7,4],
[2,4,6],
[8,5,9,3]
];
haxe.Timer.measure(function() {
var sum = 0.0;
for ( i in 0...10000000 ){
sum += Solve(array);
}
trace(sum);
});
}
static private function Solve(t:Array<Array<Float>>):Float
{
for ( idxLine in (1...t.length) ){
for ( idxCol in (0...t[idxLine].length) ){
if ( idxCol == 0){
t[idxLine][idxCol] += t[idxLine-1][0];
} else if (idxCol == t[idxLine].length-1){
t[idxLine][idxCol] += t[idxLine-1][idxCol-1];
} else {
t[idxLine][idxCol] += Math.max(t[idxLine-1][idxCol-1], t[idxLine-1][idxCol]);
}
}
}
var maxi = -1.0;
for (elem in t[t.length-1]){
maxi = Math.max(maxi, elem);
}
return maxi;
}
} |
Arrays with their bound checking don't help as well :-/ |
Is that with generics erased or without? |
Without |
Alright then, I guess that means we can close here because it has been addressed on hxcpp and is gonna be an instance of #4872 on C#. |
These benchmarks suggest to me that maybe we should be linking in something like v8 for --interp. |
HL interp does a LOT of validation checks (basically typecheck every register you assign to) in order to check that nothing is wrongly compiled. It's not been written with performances in mind, but could eventually be modified, although it would still suffer the same additional wrapping for all values that affects neko interp. |
Any reason why using
Array<Array<Float>
compiles toArray<::Dynamic>
? That reduces a lot the performances when using multi-dimensional arrays.The text was updated successfully, but these errors were encountered: