News for hackers. Stuff that matters.
Re:Why Discord is switching from Go to Rust by masklinn on Tuesday February 04, 2020 @03:47PM (#22240783)
Maybe by reifying the indirection? The compacting arena would hand out smart pointers which would either always bounce through something (to get from an indentity to the actual memory location, at a cost) or it'd keep track and patch the pointers it handed out somehow.

Possibly half and half, I don't remember what language it was (possibly obj-c?) which would hand out pointers, and on needing to move the allocations it'd transform the existing site into a "redirection table". Accessing pointers would check if they were being redirected, and update themselves to the new location if necessary.

edit: might have been the global refcount table? Not sure.

Re:Why Discord is switching from Go to Rust by steveklabnik on Tuesday February 04, 2020 @03:54PM (#22240841)
Yeah so I was vaguely wondering about some sort of double indirection; the structure keeps track of "this is a pointer I've handed out", those pointers point into that, which then points into the main structure.

I have no idea if this actually a good idea, seems like you get rid of a lot of the cache locality advantages.

Re:Why Discord is switching from Go to Rust by mypalmike on Tuesday February 04, 2020 @05:29PM (#22241772)
This sounds a lot like classic MacOS (pre-Darwin) memory allocation. You were allocated a handle, which you called Lock on to get a real pointer. After accessing the memory, you called Unlock to release it. There was definitely a performance hit for that indirection.
Re:Why Discord is switching from Go to Rust by cesarb on Tuesday February 04, 2020 @06:04PM (#22242095)
It's the same on classic Windows (pre-Windows 95) memory allocation. GlobalAlloc with GMEM_MOVEABLE or LocalAlloc with LMEM_MOVEABLE returned a handle, which you called GlobalLock or LocalLock on to get a real pointer. After accessing the memory, you called GlobalUnlock or LocalUnlock to release it. Of course, this being Microsoft, you can still call these functions inherited from 16-bit Windows even on today's 64-bit Windows. (See Raymond Chen's "A history of GlobalLock" at https://devblogs.microsoft.com/oldnewthing/20041104-00/?p=37...).
Re:Why Discord is switching from Go to Rust by masklinn on Tuesday February 04, 2020 @04:00PM (#22240902)
I don't know that the cache locality would be a big issue (your indirection table would be a small-ish array), however you'd eat the cost of doubling the indirections, each pointer access would be two of them.
Re:Why Discord is switching from Go to Rust by e_y_ on Wednesday February 05, 2020 @04:14AM (#22245210)
On top of the cost of the extra pointer lookup, you also run into cache coherency issues when dealing with threading. So then you need to use atomic ops or locks or cache flushing which makes it even more expensive.

Rust is better suited to deal with it since there's a similar issue with refcounting across threads, so you might be able to get away with doing it for objects that are exclusive to one thread.

Re:Why Discord is switching from Go to Rust by konstmonst on Wednesday February 05, 2020 @10:08AM (#22247283)
I would give out handles and have a Guard Object, that allows you to get smart pointers from handles as long as Guard Object is in scope. Then when Guard Object is out of scope, the smart pointers would get invalidated.