What affects the speed of my code?
My code is searching a game tree and I'm trying to figure out why it is so slow using the profiler. Do I look at CPU or memory or GC? I was told that heap allocation is bad as my game tree is huge and constantly cloning heap memory will slow me down significantly.
32 Replies
For some reason the profiler has the memory blank

well this view doesn't really "profile" anything. what you want to do (and i believe have already done in another post) is actually run your code with the profiler attached, and then (perhaps repeatedly) run the code that's taking too much time for your liking
how would that work?
how do you mean?
rn i just do Alt+F2 and tick the profiler box
how do i attach the profiler to the code
alt+f2 seems right

im just ticking the boxes

the blank one is this

and then you start it
i did, this is what came back
i also have one for CPU
well your app is still running, the profiler evaluates the results after you're done profiling
oh
then why does the CPU have results but not the memory
i would personally tick both memory and cpu
that i can't answer
alright
can you tell me what things in general cause code to be slow? like nested loops or cloning heap memory etc.
any work takes time
the profiler can help you identify specific areas of code that are taking a long time to run
Do I look at CPU or memory or GC?
if you care about execution time then CPU is the main one to look at
but depending on the complexity of the code you may just be better off analyzing the algorithm you're using with your brain
your implementation is what determines how slow or fast some code is, it's difficult to think of "general things that make code slow"
it can have a million causes
hm good idea
searching a tree should be relatively fast as far as searching collections goes
assuming it's actually sorted and not just a random graph of objects
right now i'm counting every single node on the tree
can you share the code?
there's quite a bit
just the part doing the counting
that shouldn't be much code
well, you profiled it right? share the method(s) that took the most time/you want to improve


CPU usage was spread evenly across these 4 functions, with a huge empty space for the remaining 1/5

this is MakeMove()
okay so it doesn't just count the nodes
does this method even return anything other than
0
?it counts the legal nodes
this is a chess engine
i mean, determining what's legal is more than counting
oh i suppose you are right
determining legal is IsInCheck()