Re:Proving that Android’s, Java’s and Python’s sorting algor...
by tedunangst on Tuesday February 24, 2015 @09:40AM
(#9100742)
Sounds like the amount of memory involved is quite small. Below a certain threshold, doubling is practically free. And IIUC even over-allocating memory doesn't necessarily mean it uses all of the memory, only for the the inputs that cause the bug. The extra comparison however would be performed for all inputs.
[ Parent
| on HN ]
Re:Proving that Android’s, Java’s and Python’s sorting algor...
by rozim on Tuesday February 24, 2015 @11:03AM
(#9101388)
Below what threshold though? L1 cache size? O(64 bytes), no?
Re:Proving that Android’s, Java’s and Python’s sorting algor...
by nostrademons on Tuesday February 24, 2015 @01:00PM
(#9102326)
Depends upon the operation of the rest of the program. 64 bytes is the size of a cache line, the actual L1 cache (on recent Intel processors) is 1024 of those cache lines. If the extra memory just means that you pull an extra line into cache for a bookkeeping array, the effect is negligible. If it means that you thrash the cache and have to evict some of your sorted data, the effect could be orders of magnitude.
I'd really hope that the JDK maintainers benchmarked against real-world programs before deciding which fix to use. My intuition is that the set of programs where increasing the memory usage matters is tiny, but the effect is large for them - it's the set of programs where the working set is greater than the L1 cache size. Equality comparisons aren't free either, they can often cause branch mispredicts. But the point is that performance tuning on real-world programs is very counterintuitive, and so the best way to do it is to run some actual numbers on actual programs.