PanelCompareFunc is just a sort function. It simply compares integers inside (depth values). The less widgets you have per panel, the fewer calls to PanelCompareFunc you will have. You can't avoid having those calls entirely, but the cost of doing so is minimal, so not sure why you are even bringing it up. All I can think of is maybe you did a deep profile, which would be a mistake to base your findings on. Deep profile adds a static amount of overhead to every function call, no matter how small the function's execution time may be. So 1 call to a function that takes 1 ms to execute may add 0.01 ms, making it 1.01 ms in deep profile. Now 1000 calls to a function that takes 0.0001 ms to execute would normally be 0.0001 * 1000 = 0.1 ms, but in deep profile that becomes (0.0001 + 0.01) * 1000 = 10.1 ms, leading you to think that there is a problem when in fact there isn't.