High-Speed-Priority-Queue-for-C-Sharp icon indicating copy to clipboard operation
High-Speed-Priority-Queue-for-C-Sharp copied to clipboard

Support int priorities in FastPriorityQueue

Open BlueRaja opened this issue 7 years ago • 6 comments

ints are nearly always faster than floats. Given how popular this library has become, and how many people are using it for non-pathfinding applications, it would be nice to have another queue that supports int for people who don't need float

BlueRaja avatar Jun 13 '17 16:06 BlueRaja

I've actually switched to uint and ulong now. Signed values are inconvenient to work with sometimes, and I might need the extra range of 64 bits.

dougmill avatar Jul 09 '17 22:07 dougmill

Have you profiled this? My understanding is that uint is generally slower than int because the JIT isn't programmed to optimize it as aggressively (because it's not a CLS-compliant type), but I've never verified that myself.

In any case, using uint in APIs is highly discouraged because of CLS-compliance.

BlueRaja avatar Jul 10 '17 08:07 BlueRaja

I just now profiled it, and the results were mixed. Some times uint was faster, some times int was faster. int was faster more often, but the margin was never big.

In any case, performance is not among my reasons for choosing unsigned types.

I'm certainly not suggesting that you support uint instead of int, but it might be useful (especially if you get code generation working for it) to support uint in addition to int.

dougmill avatar Jul 12 '17 06:07 dougmill

Maybe you can add another class with two generic types (node and priority value) and comparison delegate (or second type must support eq, lt and gt operations). This can be a stupid idea but though

Bedivierre avatar Jan 30 '19 19:01 Bedivierre

@Bedivierre This already exists, and is what SimplePriorityQueue is built off of. Unfortunately it's ~10-15% slower than FastPriorityQueue in my pathfinding benchmarks because the JIT is not able to properly optimize the comparison

BlueRaja avatar Jan 30 '19 20:01 BlueRaja

This would also help support determinism across hardware. Please consider using long to maintain precision.

pajama avatar Sep 21 '20 15:09 pajama