3 ms·
> Just a few days ago I changed stack access to heap access in a larger generated perfect hash and got 100x better performance Link me the code so that I can s
by nlitened 1y ago
> Just a few days ago I changed stack access to heap access in a larger generated perfect hash and got 100x better performance
Link me the code so that I can show what you did wrong
- rurban 1y agohttps://github.com/rurban/cmph/commit/4bb99882cc21fd44e8660294bb329dee1840df92 https://github.com/rurban/cmph/commit/4bb99882cc21fd44e86602... I did not nothing wrong :) And I remember better now. I changed stack access to immediate global access to const arrays. And insane was the compilation time, not so much the runtime. -O2 timed out, and if it compiled it was 10x slower run-time. Now compilation is immediate. This compiles large perfect hashes to C code. Like gperf, just better and for huge arrays.
- nlitened 1y agoThank you for linking. In this case, as I understand, you switched from a local array which is re-initialized with values upon each function invocation to a global array that is pre-initialized before even the program starts. So my understanding is you're measuring the speed between repeated re-initialization of your local array and no initialization at all — not between "relative" stack access and "absolute" heap or global memory access. As I understand, to do it the way you wanted initially, your local array must be `static const` instead of just const (so that there's a single copy of it, essentially making it a global variable as well). To be honest, I am not sure why C compiler doesn't optimize it this way automatically, likely I don't know C spec well enough to know the reasons.