These are chat archives for ChaiScript/ChaiScript

23rd
Mar 2015
Andreas Reischuck
@arBmind
Mar 23 2015 10:01
Hey, I just realized that my benchmark was faked... I had changed the Test-Script to run faster in order to get errors faster and forgot to raise the loop count again. ChaiScript is still 10x slower than QtScript
It would be a good challenge to optimize the execution performance
Jason Turner
@lefticus
Mar 23 2015 14:00
Is it possible for you to reduce the code you want to optimize into a succinct example? There's a change it's the conversion operations you've provided that are slowing it down, or possible it's just some scenario I haven't optimized for yet. If you can provide a gist or something, I'll take a look at it.
Andreas Reischuck
@arBmind
Mar 23 2015 14:01
I will publish my code... nothing secret about it... Wait a day or two :)
Jason Turner
@lefticus
Mar 23 2015 14:09
I think I've gotten all of the low hanging fruit performance fixes out of the benchmarks I have today (plus some). I've already been thinking I need to add more tests to my benchmark suite. The current code base is something like 50x faster than chaiscript 1.0 (with the benchmarks I've optimized for)
I think also the next big thing will be to actually optimize the AST parse tree
eliminate "return" statements where possible, look for code that never changes and optimize variable lookups, that kind of thing
Andreas Reischuck
@arBmind
Mar 23 2015 15:25
I would suggest to remember function calls... the same call should almost always match the same function the next time it's called
I played around with ChaiScript codebase... But could not find anything that resulted in significant boosts anywhere
Jason Turner
@lefticus
Mar 23 2015 16:26
The "almost always" is the key problem
I can certainly construct examples that change each time
the second problem is where to remember it? It has to be done in a way that can be thread-safe
Andreas Reischuck
@arBmind
Mar 23 2015 17:09
I would also suggest to eliminate the throw/catch during the normal code execution
I have not measured it, but I would guess it's not ideal for performance
Jason Turner
@lefticus
Mar 23 2015 18:34
Interestingly, exceptions have virtually 0 overhead over other methods (I have measured this on a few occasions) the only differences is that they slow down the debugger, if you're running inside a debugger. It can have a huge impace there
impact
Jason Turner
@lefticus
Mar 23 2015 18:51
but I know it's annoying / confusing for users of MSVC, so it's on my to-do list
that's the kind of impact difference running outside of a debugger can have, if that's related to your performance issues
Andreas Reischuck
@arBmind
Mar 23 2015 20:57

A little benchmark for this

extern int func(int x, int y);
extern int func_except(int x, int y);
int func(int x, int y) { return (x + y); }
int func_except(int x, int y) { throw (x + y); }

void TestBenchmark::calls() {
    QBENCHMARK { func(49, 430); }
}
void TestBenchmark::exceptions() {
    QBENCHMARK { try { func_except(49, 430); } catch(int x) {} }
}

result

MSVC2013 (64bit) release:

RESULT : TestBenchmark::calls():
     0.0000033 msecs per iteration (total: 57, iterations: 16777216)
RESULT : TestBenchmark::exceptions():
     0.0016 msecs per iteration (total: 55, iterations: 32768)

MSVC2013 (32bit) release:

RESULT : TestBenchmark::calls():
     0.0000028 msecs per iteration (total: 96, iterations: 33554432)
RESULT : TestBenchmark::exceptions():
     0.0041 msecs per iteration (total: 68, iterations: 16384)

MINGW GCC491 (32bit) release:

RESULT : TestBenchmark::calls():
     0.0000025 msecs per iteration (total: 86, iterations: 33554432)
RESULT : TestBenchmark::exceptions():
     0.0068 msecs per iteration (total: 56, iterations: 8192)
As you can see the exceptions are really expensive compared to normal flows
Andreas Reischuck
@arBmind
Mar 23 2015 21:10
Doh, That's not the code...
void TestBenchmark::calls() {
    int r = 1;
    QBENCHMARK { r *= func(49, 430); }
}
void TestBenchmark::exceptions() {
    int r = 1;
    QBENCHMARK { try { func_except(49, 430); } catch(int x) { r *= x; } }
}
Andreas Reischuck
@arBmind
Mar 23 2015 21:53