Skip to content

Conversation

@gstarikov
Copy link

when using golang allocations are very slow and all optimizations start with using pools and other ways to minimize allocations. try this version. it is functionally equivalent to yours except for allocations. instead of placing objects on the heap, copying via the stack is used (and the compiler optimizes it well)

@platonvin
Copy link

Nice observation! This is because compilers are allowed to optimize stack a lot more than a heap. But i think using pointers (dynamic memory) was part of the benchmark. Take extreme example - if everything was comptime (const size arrays on stack), compilers would just optimize away all the benchmark and hardcode precomputed number.
(i thought that would be fun to bench, here are results in comparison with other languages: https://github.com/platonvin/benchmark-c-vs-all/tree/less-dynamic)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants