Hacker News new | ask | show | jobs
by bnegreve 1144 days ago
Damn, it took me years to accept that dropping C-style or C++-style explicit memory management in favor of garbage collection was an overall improvement. And now we have to reuse and mutate objects instead of creating new ones because of it.
2 comments

The React style forces a lot more object creation and copying then you're probably imagining. If you want to update an array, you generally have to make a new array, and copy over all the data except for your mutation: https://react.dev/learn/updating-arrays-in-state

If you, for example, hold your voxel level data in a big array, that means copying that data every time the level is modified.

"The React style forces a lot more object creation and copying then you're probably imagining."

Its not react style its literally the core of how react works(immutablity). To rerender a component you need the new state to point towards a new reference to an object/array (hence the copying data to a new array) because JS compares objects/arrays through reference and not value. Not exactly react's fault but how JS works.

I said "react style" because they are not using React in a conventional way: https://github.com/kevzettler/react-regl
I can see the need for memory management for a game. There are other things, also graphics related like map points or point clouds.

You are more likely to a struct of arrays than an array of structs/objects as well. Very handy in C but also JS.

I suppose you can use a sliding window object (or “fly” object) that pretends to be the object when the data is really split across various arrays, just don’t actually loop over them. ;) I bet someone has done a library for something this way and used proxies.