d3/d3-array

d3.ticks crashes with very large counts

anbnyc opened this issue · 3 comments

On Chrome 83 / MacOS Catalina, my browser crashes when I pass an arbitrarily large value (~70 million) to as the count argument to d3.ticks. I reproduced this issue here: https://observablehq.com/@anbnyc/limits-of-ticks. On D3 slack, @Fil suggested that the function could buy a little extra space by switching to Float64Array above very large numbers on https://github.com/d3/d3-array/blob/master/src/ticks.js#L20 and https://github.com/d3/d3-array/blob/master/src/ticks.js#L26.

I'm quite curious, what is the motivation for passing in such a large number?

I feel this is expected behavior. It’s the caller’s responsibility to request a “reasonable” number of ticks based on available memory and desired compute time.

Fair enough. This came up while debugging a program where that argument is set dynamically as the product of two inputs, which are typically within a reasonable range, but in some edge cases could end up very big. The fix was just to put a max on the value getting passed, which is totally sufficient.