Repository navigation
Description
I've been recently playing around with Octane and exploring what code it generates, and I found two limitations that impact my potential use-cases for it, and they both have to do with automatic dependency array generation. Thankfully I can always provide a manual dependency array, but perhaps there is something that could be done here to mitigate my problems with the current resulting code.
Diffing only the tail of a chained property access
Reproduction: Link to playground
Say we have the following code inside a component:
const [count, setCount] = useState(0);
function handleClick() {
setCount((prev) => prev + 0.25);
}
const fixed = useMemo(() => count.toFixed(2));
fixed could be computed during render, but for the sake of the argument, let's say it's an expensive computation that we want to recompute only when count changes. With the current setup, the dependency array is generated to be [count.toFixed], which is a function that lives on Number.prototype, and doesn't change when count changes, which causes the value of fixed to be stuck at 0.00.
A potential fix for this would be to include each part of the access chain in the array, which in this case would be [count, count.toFixed]. It could on the other hand trigger false positives when accessing props: [props, props.foo] as props is most likely a new object on every rerender of the parent.
Getters with side-effects
During my exploration, I tried to integrate TypeGPU and it worked very smoothly, however I cannot rely on automatic dependency array generation there because properties have to be accessed in a specific context.
const timeUniform = useMemo(() => root.createUniform(d.f32, 0));
const hueUniform = useMemo(() => root.createUniform(d.f32, 0));
const pipeline = useMemo(() => {
return root.createRenderPipeline({
vertex: common.fullScreenTriangle,
fragment: ({ uv }) => {
'use gpu';
const time = timeUniform.$;
const hue = hueUniform.$;
return d.vec4f(getColor(uv, time, hue), 1);
},
});
}, [timeUniform, hueUniform]);
// ^ explicit dependency array to not prematurely access .$ on resources
In TypeGPU, accessing .$ on resources is equivalent to dereferencing in shader code, and doing so outside of shader functions is illegal. I am sure that this is a hard problem to solve, as there is the prior limitation that has the exact opposite problem, I just wanted to bring this limitation to your attention.
Activity
leonidaz commentedon Aug 3, 2026
fixed by #552 and #553
Thanks for reporting!
Obviously we won't be able to auto-detect every possible use case and for those cases explicitly specifying a dependency array would still be needed, but we definitely can solve for one level object access in issue 1 and tracking the
use gpudirective to only auto-track the identifiers themselves without their properties in your issue 2.iwoplaza commentedon Aug 4, 2026
Thanks for the fast response, I really appreciate the improvements! 🙏💜