Lurker News

Comments (85) 14 threads

Earlier comments
nnevatie3 replies#
> Java

Well, there's your first problem, when it comes to performance. Let's not kid ourselves - JVM is great, but it doesn't hold a candle to optimized native code.

trickypr2 replies#
I don’t think this is fair? Java isn’t that slow, so long as your task isn’t long running (give JIT time to get going) and isn’t doing anything insane like reflection.

I don’t doubt that the C++ code base may end up faster, but probably because tangential optimisations (like the author’s lock free programming, or more intelligent memory allocations) rather than because the same code runs significantly faster.

Narishma2 replies#
One place where it's definitely worse than C++ is memory usage.
pjmlp#
Depends in the C++ skills, and how the code looks like, from "C with a C++ compiler" up to "worthwhile of a CppCon talk".
marginalia_nu1 reply#
Regardless whether you're coding in C++ or Java, this sort of code needs to use scratch allocators or pooled objects everywhere that matters. Both languages have some nominal support for this via e.g. std::pmr and SegmentAllocator but I wouldn't stretch as far to say either feels idiomatic.

Continue this thread — 1 reply

cpgxiii1 reply#
The biggest difference is that you would not be writing the same code in both Java and C++. It's an exaggeration, but writing "Java in C++" would be passing every non-trivial parameter as a shared_ptr. Of course no one in the C++ community would think this was a good choice, and you generally only ever encounter ownership this messy in really old or weird libraries. The language simply gives you more ways to express ownership and memory layout/locality in idiomatic ways, whereas achieving similar behavior in Java is much less trivial. For nontrivial programs, memory layout and locality has a very significant affect on performance; rarely are you going to have a program that spends all of its time bound by ALU/FPU performance (but when you do, that control over layout means C++ has long had very capable libraries for SIMD math, where adding it to managed languages has been a much more recent addition).

Really the only thing that's well known to (potentially) be faster in Java is certain lock-free datastructures where the JVM GC essentially allows object cleanup to be trivially deferred out of performance-critical points. You can do the equivalent of this in C++, but it generally requires care and it looks very weird.

pjmlp#
Java is 1990's C++ way of programming, thus it isn't writing Java in C++, it is writing C++ just like the community was doing with OWL, VCL, PowerPlant, CSet++, MFC, Motif++,... before 1996.

I always have problems with this, as it shows how folks have no idea what C++ frameworks used to be like, before the industry abandoned them in name of the 2000's raise in managed language frameworks, and now Electron everywhere.
All those J2EE, ASP.NET, Swing, Forms, Django, Rails and co, had some kind of C++ predecessor.

pjmlp#
It works great for Amazon and Netflix, some people can, others don't.
marginalia_nu2 replies#
(Author). So I've gotten pretty far in the index translation, at least as far as the postings lists go. Out of the box for a direct translation there really hasn't been much performance improvement going from Java to C++ in benchmarks.

The Java code was already stupidly optimized and basically allocation free in the hot paths apart from stuff that stays in TLAB or gets trivially elided. And while Java in general is unwieldy as hell for systems programming, it's often surprisingly competitive since the C2 JIT basically gives your system free PGO everywhere on real world data.
The performance impact I've seen has mostly been the design improvements I've found along the way . Paring the index down to now ~2000 lines of C++ has let me find several design refinements that improve buffer pool performance by using more lock free algorithms, improving the index layout to reduce unnecessary block fetches and allowing more accurate prefetching, etc.

xmcqdpt21 reply#
That’s been my experience too.

At $work we’ve often gotten performance improvements from rewriting C++ code into Java. Every time it’s because rewriting code from Java to C++ requires deeply thinking about the code, which unlocks algorithmic improvements that could be ported back to the C++ version (usually we make those rewrites for other reasons than performance so we don’t actually do that.)

marginalia_nu#
Yeah the motiation for the port is still mostly ergonomics. Like it's worth it for std::span, , and TSan alone.
nnevatie#
Optimized code is rarely a direct translation from Java. C++ provides you access to a new world with SIMD, optimized allocators, cache-aware memory layouts, etc.

Performance should be part of the design, not something you pop in as an afterthought by micro-optimizations.

potato-peeler5 replies#
> My friend in Christ

I have always wondered where this expression came from? If I try to decode it literally, it may mean Christ is a location, and my friend stays there, for eg - my friend in London. Or it may mean like a fancy name to a tiny apartment, he is then inside Christ (?). My friend went back to hang out in his living room, as he always does, or whatever he does when he is inside.
But this grammar is also weird. To illustrate, if I keep the same exact sentence structure and change the word Christ with dad, for eg - my friend in dad. That actually sounds sweet. Not lot of us can say we see a friend in our dad! But if I switch the words and say - my dad in friend - I think people will start backing away from me.
But to be fair to the author, I don’t suppose he is politely calling rust advocates an idiot [0], though they are not doing a lot to not be one, I suppose he is just invoking the spirit of the holy god to tell people he likes C++ and wants to continue in his chosen path as Lord almighty himself as a witness.
[0] - http://my-brother-in-christ.urbanup.com/17301143
—-
Have you considered using go?

sph1 reply#
“In Christ” might be a synecdoche, a literary device in which you use the part to refer to the whole.

Thus, “My brother in Christ” is usually intended to be “my brother in the Christian sense”, as in, “My brother, and I call you my brother because we all are brothers under Christ, please understand this…”
It is an amusing memetic figure of speech. Please update your database records and neural weights accordingly.

potato-peeler#
> a literary device in which you use the part to refer to the whole

I always thought it was about the different levels of stupidity, for eg -

    If someone makes a small mistake, you will say - my guy...
    If someone make a bigger mistake, you might say - dude, seriously...
    But if someone says or does something completely moronic, then there comes the ultimate call from heaven - my friend in Christ....
It represents the escalating level of your stupidity.

Jesus is the final boss of disappointment!
I suppose it is the HR approved version of - listen here you little shit...

lelanthran1 reply#
> But this grammar is also weird. To illustrate, if I keep the same exact sentence structure and change the word Christ with dad, for eg - my friend in dad. That actually sounds sweet. Not lot of us can say we see a friend in our dad! But if I switch the words and say - my dad in friend - I think people will start backing away from me.

You're overthinking it; "Friend in Christ" is pretty much the same as "Brothers in Arms" or "Friend in Need" or "Partner in Crime". It's a common phrasing, and English speakers generally decode the meaning behind it.
For example, if I said "My comrades in misery", people would readily understand it.

potato-peeler1 reply#
> You're overthinking it

My friend in Christ, I suppose you have to think about something just the right amount to say what you want to say. If you think about it, anything given an extra effort is worth applauding, for eg over achieving. It is always impressive if you achieve little bit extra. In a way you have to overthink, if you want to over achieve. No?

lelanthran1 reply#
My Partner In Crime, you make a good point, but allow me this rejoinder:

> It is always impressive if you achieve little bit extra. In a way you have to overthink, if you want to over achieve. No?
Yes, agreed. However, here is a different PoV.
Under thinking: "My Friend In Christ is easily understood and not weird".
Thinking about it: "This does not make any sense, and is weird."
Overthinking it: "Superficially, sure, it is weird, but looking the broader context, it obviously fits in with general usage of the language, thus it is not weird"
So we go from "underthinking concludes not weird" to "thinking concludes weird to finally "overthinking concludes not weird.
(IOW, I guess I'm guilty of overthinking much more than the post I replied to, so if you think overthinking things is a good thing, then I guess I agree, because I did that too).

Continue this thread — 1 reply

marginalia_nu#
It's just an archaic address with dated grammar. People still use it today, regardless.

It's like "god be with you" isn't really anything anyone would say today, even though we still say "goodbye".

PeterHolzwarth#
Partner in crime. Brother in arms.
jonjacky#
I think he is suggesting that his critics are acting holier than thou, saying to him, "I am a more conscientious programmer because I use a memory-safe language"

All comments shown.