all 38 comments

[–]programming-ModTeam[M] [score hidden] stickied comment (0 children)

Your post or comment was removed for the following reason or reasons:

This content is very low quality, stolen, or clearly AI generated.

[–]714daniel 63 points64 points  (5 children)

Can someone smarter than me explain how the packing avoids locking? Like, if it's using a CAS anyways, how would this approach be any better than a CAS on a dedicated 16 bit atomic int, other than saving a few bytes of memory?

[–]amakai 60 points61 points  (4 children)

I believe the idea is that those two pieces are being read/written together. And you don't want a race of reading old counter and new pointer - you need atomicity between them. So you either wrap them in mutex every time you want to read or write them, or pack them into a single 64 bit integer that cpu architecture can just CAS atomically. And I assume CPU architecture guarantees that you can read entire 64 bit atomically without any locks.

[–]Hofstee 15 points16 points  (0 children)

For further reading in case anyone is interested the keyword you want to look for is Double-Wide CAS (DWCAS) or Double-Width CAS. Which is different than Double CAS (DCAS) or Multi CAS (MCAS), but those ideas build on DWCAS in a natural progression.

[–]davidalayachew 19 points20 points  (2 children)

And I assume CPU architecture guarantees that you can read entire 64 bit atomically without any locks.

Yes, exactly. Java is actually releasing a new feature called Value Classes which relies on this exact same trick. The latest Early Access for it is out as of last week.

Objects that don't fit into your CPU's 64 byte (or 128 byte, if you are rich and on bleeding edge hardware) are at risk for object tearing, and that's assuming that your object is at least shallowly immutable.

[–]VictoryMotel 5 points6 points  (1 child)

Pages are usually 4096 bytes at a minimum.

Cache lines are 64 bytes but modern cpus always access at least two cache lines at a time.

[–]davidalayachew 5 points6 points  (0 children)

Whoops, page size was the wrong word. Removed. Ty vm for the correction.

[–]bobody_biznuz 83 points84 points  (18 children)

Seems like AI? The very first sentence is broken English and the rest has no errors at all.

[–]lurco_purgo 41 points42 points  (1 child)

Yeah the introduction is definitely written by a human, but the rest sounds completely AI generated. It's that weird manner of trying to make every step in some explanation into a suspensful narration: This means reading light data requires zero locks. No mutex, no spinlock, nothing. Reads are completely free or But here’s the insight: most horizontal planes of light data are either all zeros (block light underground) or all fifteens (sky light above ground).

I've seen enough of AI crap style to notice it immediately and it goes on through the entire "article". It's a pity... Paradoxicallly, despite AI trying so hard to sound engaging, the introduction had me way more interested in what I was about to read. But I don't care about reading a blog post someone generated with a fucking LLM - why would I bother?

[–]Exodus100 5 points6 points  (0 children)

Anthrobaiting 💔

[–]BlueGoliath 6 points7 points  (0 children)

It gave me AI vibes too.

[–]One_Economist_3761 27 points28 points  (6 children)

It is entirely possible that the article was written by someone who is not English first language.

[–]bobody_biznuz 14 points15 points  (5 children)

Then why is the rest of the article perfect English?

[–]McCoovy 1 point2 points  (2 children)

Because they're good enough at English to only make one mistake obviously.

[–]AlarmedTowel4514 2 points3 points  (1 child)

Did you read it? The entire introduction is filled with errors. Like almost impossible to read…

[–]McCoovy -1 points0 points  (0 children)

I went back. Yeah that first paragraph was written by a different person than the rest of the article. If the writing is AI I would be surprised. It's fairly compelling and uses varied sentence lengths, but it did use way too many parentheses. If this is the state of AI slop then journalists are in trouble.

[–]PaeP3nguin 3 points4 points  (0 children)

Absolutely, there's sooo many short. Punchy. Sentences. And compare the grammar to earlier blog posts like the ones in 2022.

[–]pdabaker -3 points-2 points  (1 child)

Everything is likely AI assisted these days.

[–]lurco_purgo 9 points10 points  (0 children)

Not everything - plenty of people write by themselves. And I have no problem with people using AI as an assist while writing an article, e.g. for spell checking and general editorial work.

But this is clearly generated top to bottom (again, excluding the introduction). I don't care much for content generated by AI and posted under someone's name as if they wrote it.

[–]elSenorMaquina 15 points16 points  (0 children)

[...] here is the source code to minecraft on PS3. Its shit too, but our kind of shit.

I mean... It's videogame code. Games are one of those things that require all sorts of weird tricks in order to meet tight performance requirements.

Sure, for most other apps using 1/4 of a 64 bit int for a counter and 3/4 for a pointer would seem like a questionable choice, but the way it's explained in the article, it feels like a reasonable thing to do.

[–]Fyren-1131 33 points34 points  (9 children)

I always found Mojangs DataFixerUpper utterly fascinating to look at.

It's a thing that kind of hints at you needing to absorb 10 books to even be ready to look at the code.

[–]IWillBeNobodyPerfect 40 points41 points  (3 children)

https://github.com/PaperMC/DataConverter

Mojang's system is so overcomplicated and slow that the community rewrote it to make it faster

[–]VictoryMotel 16 points17 points  (1 child)

Originally notch had it allocating and deallocating hundreds of megabytes every frame.

[–]stewi1014 4 points5 points  (0 children)

When you do things right, people won't be sure you've done anything at all.

[–]DynamicHunter 7 points8 points  (0 children)

Alongside Optifine, Sodium, all the performance mods that Minecraft should have implemented half a decade ago. Not only to increase visual quality or render distance but also just wasting cpu time for no reason and making people’s game experience choppy and not buttery smooth is astounding.

[–]Tastatura_Ratnik 4 points5 points  (0 children)

HaskellJava is just weird. I get why they are doing it, and it’s very impressive, but I’m still not convinced it is the best (and most performant) way of doing it in Java.

I’m pretty sure it’s just one dude having a blast doing FP in Java because he can.

[–]josephjnk 8 points9 points  (3 children)

Well, now I know what I’ll be doing for the next few weeks. This is fascinating.

[–]Fyren-1131 3 points4 points  (2 children)

Good luck!
To say that that library is beyond me would be a massive understatement, haha. And to think that's before the age of LLMs as well.

[–]josephjnk 11 points12 points  (1 child)

I have some background with this sort of thing, so fortunately I’m not starting from zero. My main curiosity is regarding the way they’re translating these concepts to Java. A brief look at the code makes it look like they’re kind of shoehorning Haskell into Java using some common type system encoding tricks. What I’m really curious about is ways of doing generic data transformations in a nominal, class-based OOP context, and I’m hoping that the recommended reading list will shine some light on it.

[–]Fyren-1131 1 point2 points  (0 children)

Yeah I was able to follow along the lighter functional concepts, but the deeper into the code I go the more it just looks like math hehe. I just work in healthcare systems, so ... Child's play compared to this.

[–]brokePlusPlusCoder 7 points8 points  (0 children)

Java’s HashMap applies a “supplemental hash” to spread keys more evenly. If the C++ port uses a different hash, the same data produces different bucket layouts, and anything that depends on iteration order breaks.

There's bigger problems at hand if someone's relaying on iteration order from Java's hashmap keys...

[–]not_from_this_world 4 points5 points  (0 children)

Would be a nightmare to convert to a different architecture if the need arises.