Hacker News new | ask | show | jobs
by rocqua 689 days ago
How come the CoW method requires runtime reference counting? A lot of the same benefit (but not all) should be available based on static analysis right?

Especially if the approach isn't really Copy on Write, but Copy only when someone might want to use the old value. Default to trying to mutate in place, if you can prove that is safe.

For most locals, that should be rather doable, and it would be a pretty big gain. For function parameters it probably gets hairy though.

1 comments

> How come the CoW method requires runtime reference counting?

Because it doesn’t do copy-on-read, you have to know whether there are references other than yours that can read the data. A single bit “at some time there were at least two references to it” doesn’t suffice, as it would mean you can’t detect when the last reference goes away, so it would leak memory (lots of it)

> A lot of the same benefit (but not all) should be available based on static analysis right?

That’s an (very important) implementation detail that makes reference counting perform reasonably well. You don’t want increase-decrease cycles in tight loops, for example.