3 ms·
You should look at the assembly to know for sure (after you have profiled and narrowed it down). With this sort of speed difference my guess is that there is e
by CyberDildonics 9y ago
You should look at the assembly to know for sure (after you have profiled and narrowed it down).
With this sort of speed difference my guess is that there is either excess memory allocation going on, pointer hopping when you think you are using something by value on the stack, or both.
- maxxxxx 9y agoI'll second looking at the assembly code. I had a similar problem a few years ago and an assembly expert told us that we were moving data in and out of the cache all the time instead of leaving it there. We had to change the way we looped through arrays and got a huge improvement. this could be wrong but I would also guess that the Swift optimizer is not as good as the ones C++ has mainly for the reason that it's newer.
- CyberDildonics 9y agoYou don't need to look at assembly to avoid cache misses, you just need to understand what the language is doing under the hood in a general sense, then make sure you access memory in a way that it can be prefetched. My guess is that it is either the program being written slightly differently or that swift is doing some sort of indirection under the hood.
- maxxxxx 9y ago"you just need to understand what the language is doing under the hood in a general sense" Isn't the best to find out to look at the assembly? How else can you know what the compiler and optimizer are doing?
- CyberDildonics 9y agoNo, understanding what the language is doing is not the same as looking at assembly or even understanding what the optimizer is doing. If swift is creating some variables on the heap and/or creating virtual tables for inheritance (I don't know much about it) then you don't need to look at the assembly to know that you are creating indirection or doing too many heap allocations.
- drew-y 9y agoThanks for the advice! I'll look into that. I have not spent much time in assembly land so it should be an interesting lesson.