News for hackers. Stuff that matters.
Re:Sub-10 ms Latency in Java: Concurrent GC with Green Threads by pjmlp on Wednesday August 05, 2020 @10:00AM (#24060812)
On the other hand it requires jumping through hoops to make borrow checker friendly architecture designs, or fiddle your code base with Rc<> types everywhere.

And when their count reaches 0, you have your stop the world, unless you move the destruction into a background thread, thus manually emulating a tracing GC.

Re:Sub-10 ms Latency in Java: Concurrent GC with Green Threads by pkolaczk on Wednesday August 05, 2020 @10:31AM (#24061176)
When RC drops to zero it is not STW. It is stop the current thread only. And even that can be trivially solved by background deallocation. Solving latency problem of GC is far from trivial.
Re:Sub-10 ms Latency in Java: Concurrent GC with Green Threads by pjmlp on Wednesday August 05, 2020 @11:23AM (#24061820)
As if stop the current thread isn't the world the world in single threaded programs.

I explicitly mentioned how moving into a background thread is poor man's tracing GC.

Languages like D and C# offer mechanisms for deterministic deallocation, while keep the productivity of a tracing GC.

Re:Sub-10 ms Latency in Java: Concurrent GC with Green Threads by orneryostrich on Wednesday August 05, 2020 @01:08PM (#24063082)
But if your program is single-threaded, you don’t need an `Rc` type. The whole point of `Rc` and `std::shared_ptr` is so an object can have one owning pointer per thread, in cases where you’re not sure which thread will finish using the object last.
Re:Sub-10 ms Latency in Java: Concurrent GC with Green Threads by pjmlp on Wednesday August 05, 2020 @03:38PM (#24064697)
Sure you do, try to implement a Gtk-rs application without the Rc<RefCell<>> dance for widgets state.
Re:Sub-10 ms Latency in Java: Concurrent GC with Green Threads by pkolaczk on Wednesday August 05, 2020 @02:57PM (#24064251)
Finalizers (IDisposable) or try-with-resources are not equally strong as deterministic destruction in C++ or Rust. Or did you mean a different feature for deterministic destruction in C# that I don't know of? I'm quite curious.
Re:Sub-10 ms Latency in Java: Concurrent GC with Green Threads by pjmlp on Wednesday August 05, 2020 @03:37PM (#24064681)
You can stack allocate objects, so those are alive just until the end of the stack.

Then there native memory allocation and safe handles.

IDisposable and Finalizers aren't the same thing, actually, although they happen to be used together as means to combine deterministic destruction alongside GC based destruction.

You can also make use of lambdas or implicit IDisposable implementations via helper methods, that generate code similar to memory regions or arenas in C++, but in .NET.

Finally, many tend to forget that .NET was designed to support C++ as well, so it is also possible to generate MSIL code that ensures deterministic destruction RAII style, naturally this falls into a bit more advanced programming, but it can be hidden away in helper classes.

Re:Sub-10 ms Latency in Java: Concurrent GC with Green Threads by algorithmsRcool on Wednesday August 05, 2020 @06:49PM (#24066455)
> You can stack allocate objects, so those are alive just until the end of the stack.

Well, not really. You cannot stack allocate anything but primitive buffers. So no objects or even strings. So it cannot replace heap allocation for anything but smallish "arrays" of simple types like char and int. This also means you can't use normal structs/value types, only primitives.

> You can also make use of lambdas or implicit IDisposable implementations via helper methods, that generate code similar to memory regions or arenas in C++, but in .NET.

> Finally, many tend to forget that .NET was designed to support C++ as well, so it is also possible to generate MSIL code that ensures deterministic destruction RAII style, naturally this falls into a bit more advanced programming, but it can be hidden away in helper classes.

I'm pretty sure there is no way in C# or in MSIL to explicitly free/deallocate a heap allocated object.

MSIL defines a Newobj opcode, but no Freeobj or anything like it that I have ever seen. You can use custom allocators or unmanaged memory to deterministically allocate and free buffers of structs/values types. But only those that do not include references to managed object references, otherwise you would need to pin and the references yourself and keep the GC aware that there were non-tracked references to those objects. It gets messy fast.

Re:Sub-10 ms Latency in Java: Concurrent GC with Green Threads by pjmlp on Thursday August 06, 2020 @02:04AM (#24068494)
It is so easy, write the code that you want in safe mode C++/CLI, get the code template, then implement the helper classes to generate the same MSIL on the fly.

As for stack allocation, apparently you missed structs.

Here is your string allocated on the stack.

    unsafe struct cppstring
    {
        const int BuffSize = 1024;
        fixed char data[BuffSize + 1];
        int current;
        
        public cppstring(System.ReadOnlySpan<char> buffer)
        {
            for (int i = 0; i < System.Math.Min(BuffSize, buffer.Length); i++)
                data[i] = buffer[i];
            current = 0;
        }
    }

    public class StackDemo {
        public void Myfunc() {
            var str = new cppstring ("Hello from stack");
        }
    }
Providing std::string like operations is left as exercise for the reader.
Re:Sub-10 ms Latency in Java: Concurrent GC with Green Threads by algorithmsRcool on Saturday August 08, 2020 @08:47PM (#24096418)
But that object is not a string, it is char buffer. You cannot directly substitute one for the other.

Yes I realize they can be used to store the same data, but you've defined a new type that is incompatible with an actual string object.