Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

That doesn't work if one of the arguments gets mutated


Different arguments would provide a different result, wouldn’t it?


I think this also caches closures, and recomputes them either when the inputs change or the closed over values are mutated.

Edit: Oh, apparently that's not the case... Or maybe I missed something.

http://skiplang.com/playground/#bXV0YWJsZSBjbGFzcyBGb28obXV0...

Edit2: `debug()` is tracked as an effect, causing `get()` not to be memoized. Unfortunate...

http://skiplang.com/playground/#bXV0YWJsZSBjbGFzcyBGb28obXV0...


It gets complicated as soon as there’s a pointer involved

Do you compare the pointer for equality, or do you follow it and deep-compare what’s on the other side?

What about the next pointer jump? What if there’s a class instance? What if there’s a reference cycle?

Python lets you implement custom logic in __eq__() to manually bridge some of these gaps, but doing that for everything can get out of hand. Also, deeply-traversing large objects to check equality can get arbitrarily expensive. Immutable structures simplify these comparisons (just compare everything as a value, any change will mean a new pointer), but obviously introduce certain constraints.

By tracking observed properties of mutable structures at runtime, and then publishing cache invalidations only when they change, you can:

- Do no extra work to know whether or not a cache has been invalidated

- Automatically and perfectly track everything the function “cares about”

- Track only the things it cares about, so changes to properties it doesn’t actually use won’t invalidate the cache

See the MobX docs for more (I’m not closely familiar with Skip directly, but from what I’ve seen it works on very similar principles): https://mobx.js.org/understanding-reactivity.html




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: