News for hackers. Stuff that matters.
Re:Go does not need a Java-style GC by majou on Tuesday November 23, 2021 @02:01PM (#29321778)
Max pause times of 0.5ms is what got me really interested.

It feels like a huge trade-off of GCs is almost completely gone.

https://malloc.se/blog/zgc-jdk16

Re:Go does not need a Java-style GC by masklinn on Tuesday November 23, 2021 @03:40PM (#29323191)
> It feels like a huge trade-off of GCs is almost completely gone.

FWIW the tradeoff of low latency GC is usually paid in throughput.

That is definitely the case for Go, which can lag very much behind allocations (so if your allocation pattern is bad enough the heap will keep growing despite the live heap being stable, because the GC is unable to clear the dead heap fast enough for the new allocations).

Re:Go does not need a Java-style GC by jatone on Wednesday November 24, 2021 @12:44AM (#29327248)
throughput can be fixed by adding compute. latency cannot. always optimize for latency with gc.

and no the heap will not keep growing in golang. it'll force threads to help with GC if its falling behind. thereby reducing the rate of allocations and speeding up the collection.

Re:Go does not need a Java-style GC by ohgodplsno on Wednesday November 24, 2021 @10:29AM (#29330897)
Random Go dev suddenly more of an expert than the literal best-in-class GC experts that have been working on G1GC, ZGC, Shenandoah, Parallel, ConcMarkSweep and others.

GCs are a matter of tradeoffs. Always optimizing for latency is Go's solution, but there are reasons for everything. It's the very reason why the JVM has so many knobs. Yes, it requires a PhD to know what to tune, but there are many parameters for the thousands of different situations that can arise.

Re:Go does not need a Java-style GC by jatone on Wednesday November 24, 2021 @10:46AM (#29331101)
rolls eyes I've tuned java's GC for highly available and massive throughput systems.

pretty familiar with the trade offs. java's problem isn't GC (in general) its problem is memory layout and the fact it can't avoid generating a metric shit ton of garbage.

G1GC was a good improvement and I stopped paying attention at that point because I no longer had to deal with its problems (left the ecosystem).

I'm not asserting java hasn't improved or that its GC implementations aren't modern marvels. fundamentally they're just a self inflicted wound.

golang wouldn't benefit anywhere near as much as java has from these implementations because guess what... they've attempted GC that operate under similar assumptions, young allocations, compacting patterns, etc. and they failed to make an improvement that just increasing the heap size knob wouldn't fix using the current GC.

Re:Go does not need a Java-style GC by titzer on Wednesday November 24, 2021 @07:21PM (#29336852)
> it can't avoid generating a metric shit ton of garbage.

IMHO this is an often-overlooked aspect of Java and I get flak for pointing out that Java programs are often full of defensive copying because the Java style encourages it. The JDK is very trashy and highly biased against reusing objects or doing anything in-place without creating garbage. You can't, for example, parse an integer out of the middle of a string.

15 years ago when I wrote a lot more Java, I could get away with avoiding JDK libraries to write tight and small Java code (yeah, omg, mutable non-private fields). That was how I got my AVR microcontroller emulator to beat its C competitors. Nowadays if you write that kind of code you get a beatdown.

JVMs work really hard to deal with trashy Java code. Generics make everything worse, too; more hidden casts and adapter methods, etc.

Re:Go does not need a Java-style GC by native_samples on Wednesday November 24, 2021 @06:28AM (#29328920)
Only in some kinds of apps, like web servers where all the heavy lifting is being done by the database anyway.

Consider a compiler. It's not infinitely scalable to multiple cores. It may not even be multi-threaded at all. It also doesn't care about pause times - for that you want Parallel GC.

Re:Go does not need a Java-style GC by jatone on Wednesday November 24, 2021 @10:30AM (#29330923)
depends on the compiler and language. golang seems to counter point your position quite handedly. having one of the fastest compile times and being highly concurrent.

if your application is so simple it doesn't use concurrency then 99% of the time you can completely remove the need for GC by preallocating slabs.

Re:Go does not need a Java-style GC by native_samples on Thursday November 25, 2021 @05:58AM (#29340217)
The Go compiler is fast because it doesn't do very much, not because Go's GC is good for throughput oriented jobs.

Go has repeatedly tied itself in knots over the years because they have a goal of not making the compiler slower, yet, the GC needs of the compiler are diametrically opposed to the needs of the HTTP servers Go is normally used for.

https://go.dev/blog/ismmkeynote

"As you can see if you have ROC on and not a lot of sharing, things actually scale quite nicely. If you don’t have ROC on it wasn’t nearly as good ... At that point there was a lot of concern about our compiler and we could not slow down our compilers. Unfortunately the compilers were exactly the programs that ROC did not do well at. We were seeing 30, 40, 50% and more slowdowns and that was unacceptable. Go is proud of how fast its compiler is."

Re:Go does not need a Java-style GC by earthboundkid on Saturday November 27, 2021 @12:35AM (#29357771)
For a compiler, the GC strategy that makes most sense is to never deallocate. The compiler is going to die shortly. No need to do the bookkeeping of figuring out how to deallocate before that happens.
Re:Go does not need a Java-style GC by silon42 on Tuesday November 23, 2021 @02:25PM (#29322114)
There's still a memory tradeoff, some due to GC, some due to Java (lots of runtime reflection...). Guessing 2-4x.
Re:Go does not need a Java-style GC by marginalia_nu on Tuesday November 23, 2021 @03:15PM (#29322791)
This is a bit of a tangent, but you can get into situations where Java's memory-overhead becomes pretty untenable. I was in a situation of having to keep track of ~1 billion short strings of a median length of maybe 7 characters.

In terms of just data, that should clock in at about 10 Gb; in practice it was closer to 24 Gb. I tried going with just byte[]-instances instead, which didn't help a lot. Using long byte[]-instances and indexing those doesn't help as much as you'd think because they get sliced up into small objects behind the scenes.

I ended up memory mapping blocks of memory and basically implementing my own append-only allocator.

Re:Go does not need a Java-style GC by jeeeb on Tuesday November 23, 2021 @03:54PM (#29323376)
FWIW. This would probably present a challenge in most (all?) languages.

For example in libc++ due to SSO an std::string has a minimum size of 24 bytes.

For a billion strings less than 15 chars (+ the null byte) that gets you to 24GB, and that’s optimistically assuming each string is allocated in place.

I doubt heap allocated char* would do much better either. Just having a billion 8 byte pointers eats a lot of memory. You’d really need some sort of string packing scheme similar to what you did in Java.

Re:Go does not need a Java-style GC by marginalia_nu on Tuesday November 23, 2021 @04:25PM (#29323758)
It's a lot easier to build custom allocators in C++ though.

For one, Java has a maximum mmap-size of 2 Gb, and as a cherry on top of that turd, you have no control over their lifecycle. The language is very clearly not designed for this type of work, and if you try to make it do it anyway, it fights you every step of the way.

Re:Go does not need a Java-style GC by _old_dude_ on Tuesday November 23, 2021 @06:03PM (#29324668)
It has nothing to do with the language but with the API / VM capabilities.

Both those restrictions are fixed, granted that this is not yet in the offical API, it's an incubation module (the equivalent of from __future__ of Python).

https://docs.oracle.com/en/java/javase/17/docs/api/jdk.incub...

Re:Go does not need a Java-style GC by kasperni on Tuesday November 23, 2021 @06:00PM (#29324646)
The foreign memory API which is currently incubating should help with most of these limitations: https://openjdk.java.net/jeps/419
Re:Go does not need a Java-style GC by native_samples on Wednesday November 24, 2021 @06:30AM (#29328938)
Right - specifically they invented a way to make closing an mmapped segment safe and fast. The reason you can't officially (without private APIs) unmap something in current Java is because if you did then other threads would segfault, and "no segfaults" is kind a defining characteristic of Java. The new API fixes this using more VM magic, so closing a mapping from one thread will cause other threads to throw exceptions, but this is done without sacrificing performance (it doesn't require checking a status every time you read from memory).
Re:Go does not need a Java-style GC by hashmash on Tuesday November 23, 2021 @03:40PM (#29323193)
The Lilliput project aims to address this: https://wiki.openjdk.java.net/display/lilliput
Re:Go does not need a Java-style GC by CyberDildonics on Tuesday November 23, 2021 @04:04PM (#29323517)
I would never write something like this in java, but to be fair, a program shouldn't be written like this in the first place. If you "need" a billion strings in memory and you didn't design for that with something that would scale better, you messed up a long time ago.
Re:Go does not need a Java-style GC by marginalia_nu on Tuesday November 23, 2021 @04:17PM (#29323668)
Huh, I didn't really have a problem solving the problem as it came up. Like many scaling problems, it wasn't a problem until it was. Then I fixed it. Now I have a solution that can deal with ten times as many strings as before. If I grow out of that one, I'll come up with a better design.

I could have gotten 10 times as much hardware instead, but that would be an incredible waste of money compared to just spending a few days writing more hardware-efficient code.

Re:Go does not need a Java-style GC by sitkack on Tuesday November 23, 2021 @10:38PM (#29326712)
I have addressed similar problems using a typed array of contiguous memory and another array of lengths.
Re:Go does not need a Java-style GC by marginalia_nu on Wednesday November 24, 2021 @03:30PM (#29334759)
I did try exactly that, but the GC overhead was still prohibitively high for my use case, made because big arrays in practice are composed from shorter non-contiguous arrays to make garbage collection even remotely possible.
Re:Go does not need a Java-style GC by sitkack on Thursday November 25, 2021 @06:58AM (#29340585)
Hmmm, if the typed array only contains primitives, the GC isn't looking inside the array. If the thing pointed to, can never contain a pointer, it won't need to be scanned.
Re:Go does not need a Java-style GC by lmm on Tuesday November 23, 2021 @11:53PM (#29327029)
A factor of 2.4 is extremely unlikely to be what makes the difference between a program being viable and not. You have to be in an extremely fine-tuned situation for that to make the difference, and unless your usage level is unusually static it's probably only going to make the difference for a few weeks or months.
Re:Go does not need a Java-style GC by marginalia_nu on Wednesday November 24, 2021 @06:05AM (#29328815)
So for some context, I'm running a search engine on consumer hardware. Coaxing power out of limited hardware is sort of my bread and butter. How many of these strings I can keep in memory limits how many documents I can index. Doubling that number is quite significant.

This number is orthogonal to how many searches I can serve, that is already a solved problem (through similar craftiness). Multiple searches per second sustained load is fine. The search engine has held up to the hacker news front page, which is something many supposedly non-interactive sites struggle with.

This is a non-profit operation, so unless someone just decides to pay me a months salary or two, I'm not able to meaningfully increase the hardware. I'm stuck with what I've got and will make the most of it.

Re:Go does not need a Java-style GC by lmm on Thursday November 25, 2021 @12:51AM (#29338589)
The time of someone who can do that kind of crafty tuning is almost certainly worth more than the hardware. If nothing else, I'd think having you do a week or two of consultancy and buy more hardware with the proceeds would be more efficient in terms of getting things done. (I appreciate that nonprofits have a lot of particular constraints that mean that that's probably not a practical way forward).
Re:Go does not need a Java-style GC by vardump on Wednesday November 24, 2021 @02:02AM (#29327582)
Playing a devil's advocate here: a use case might already be hitting the maximum per server RAM.

A factor of 2.4 might mean 2.4 times more hardware. You might need 240 servers instead of 100.

Re:Go does not need a Java-style GC by lmm on Wednesday November 24, 2021 @02:08AM (#29327604)
Sure. And? Everything that you need to do to manage 240 servers, you need to do to manage 100 servers. Like I said, if you're in the scaling stage then you'll be getting to 240 in a few months either way, so you need to be ready for it. 2.4x higher operating expenses matter eventually, when you're a mature organisation, but if the software is under active development you almost certainly have higher priorities.
Re:Go does not need a Java-style GC by kaba0 on Tuesday November 23, 2021 @02:48PM (#29322415)
Also, throughput. But latency and throughput are almost universally opposite ends of the same axis — that’s why it’s great that Java allows for choosing a GC implementation.
Re:Go does not need a Java-style GC by jatone on Wednesday November 24, 2021 @12:46AM (#29327252)
you can fix throughput problems by adding compute resources, you can't fix latency issues. I'll always pick a GC that optimizes latency over throughput. its easier to maintain the software.
Re:Go does not need a Java-style GC by masklinn on Tuesday November 23, 2021 @03:41PM (#29323204)
The GC memory overhead affects all languages with a GC more advanced than refcounting. It certainly does affect Go as well.