0.7.2
p5.Font.textBounds() caches its results based on the input string. this cache grows without limit and can result in crashing the browser in long-running sketches that use it.
pared-down example here: https://codepen.io/Spongman/pen/wRmzzV?editors=0010
Good catch -- I vaguely remember a fixed-size cache on an earlier todo list, but apparently never got done. Is there other such caching happening in the lib? If so, it might be preferable to adopt a uniform approach, perhaps with a memoization library.
If not, perhaps the best option is to simply disable this cache and advise users not to recompute this data for the same string/position/alignment/size etc.? The problematic use case is when it is computed each frame for the same input. Thoughts?
A couple of other issues I notice here:
1) cacheKey impl. seems broken due to lack of delimiters between args (11,111 != position 111,11)
1) it appears that cacheKey gets re-computed each time a result is cached
there are other unlimited caches that i know of, although none that i know of that are as easy to blow up like this one.
delimiters: definitely.
@lmccart any thoughts on caching/memoization going forward? Is this something we want to do generally in the lib, and if so, should we consider a uniform implementation? Or is it instead something to leave to users (with notes in docs as needed) ?
in above commit, I've fixed the cacheKey bug and disabled the textBounds cache (at least for now) @Spongman want to give a check?
@dhowe I think we'd prefer to leave caching up to users and note this in the doc
@dhowe I think we'd prefer to leave caching up to users and note this in the doc
caching is probably the wrong word, rather memoization of expensive internal functions, but nonetheless this makes sense to me (at least until/unless it causes user problems)...
Most helpful comment
caching is probably the wrong word, rather memoization of expensive internal functions, but nonetheless this makes sense to me (at least until/unless it causes user problems)...