Marginalia Search, Money, C++, Rust, AI, Stuff

(marginalia.nu)

164 points | by Curiositry 10 hours ago

10 comments

  • Const-me 1 hour ago
    “a bunch of duplicated implementations or reimplementations of stuff like sorting and searching algorithms that already exists for on-heap structures but not off” Seems modern .NET is better. Specifically, these sorting and searching algorithms can operate on spans of values. It’s easy to allocate unmanaged memory with NativeMemory.AlignedAlloc, construct spans over that memory, and use the standard library on these spans.
  • codynaut 3 hours ago
    Not wanting to learn a new language in the middle of low level work like that makes sense to me. I love C++, and a coworker has been using Rust so I'm tempted to try it, but I'd start it on a small new project and leave code I already understand alone.
    • tialaramex 2 hours ago
      That is fair. I think that despite claiming it "can not be overstated" they have in fact overstated how technical their problem is, but it's still difficult enough that it's the wrong time to go learn a new language.

      I picked up Rust very easily because it happens that although I had a long career writing C for a living I had also long ago learned the Standard ML of New Jersey (SML) and so the fact Rust is arguably an ML but disguised as a semicolon language worked out. I read the definition of core::mem::drop:

          pub fn drop<T>(_x: T) {}
      
      ... and I went "That makes so much sense. What a beautiful language" immediately.

      I would encourage you to write some Rust, maybe this Advent of Code is a good excuse if you're the sort of person who enjoys that, and otherwise some toy project of your own. Even if you ultimately don't enjoy Rust, learning it will almost invariably provoke insights that remain relevant in C++.

  • cowlevel 9 hours ago
    I'm embarrassed to have forgotten about Marginalia recently. Is it still the web's best search engine within its domain?
  • gspr 5 hours ago
    If the marginalia guy sees this: thank you from the bottom of my heart for writing this. Specifically the AI stuff.

    In a time when more and more people I highly respect are jumping on the bandwagon, the soul-draining aspects of said bandwagon are magnified. It's reassuring and heartwarming to hear the reasoned voices of likeminded people amidst the cheering crowd.

    It means more to some of us than you might realize.

    (PS: what you write about programming languages is also highly commendable! I say this as a Rust fan. You choose the technology for your thing, and the criteria are set by you. To hell with trends. Everywhere.)

    • delis-thumbs-7e 5 hours ago
      I second all of this. It was joy to read.
    • equinumerous 1 hour ago
      I really appreciated this part:

      > I don’t think such angles of attack do much to convince anyone who isn’t already convinced—if AI did the translation I sure as heck couldn’t go on to then maintain that code

      I wish more software engineers thought this way. There is too much slop flying around these days.

      • gspr 1 hour ago
        Indeed. I think part of the problem is that in a lot of cases, it isn't "I" who have to maintain the code at all. It's "us", or even better, "them". Pushing the problem onto someone else's budget is a strong force!

        And in the cases where it is actually "I", a lot of people seem to think that you can leave that to the AI, too. At which point I'm beginning to wonder whether your software actually works without the AI. It is, at least to me, insane for someone who believes in e.g. FOSS to accept a proprietary remote LLM as part of your dependency chain. And when it's not FOSS, it's also insane for your customers to accept that same premise.

  • wannabe44 9 hours ago
    > I’d be on the hook for an AI subscription perpetually hoping and praying the token prices wouldn’t ever go up. This is a nonstarter for the same reasons the search engine runs on its own hardware and not in the cloud. You can’t be truly independent if you’re subject to the whims of a landlord.

    This is the redpill of our times.

    • m-i-l 4 hours ago
      The author's "popular future predictions about AI" list misses off what I would have thought would be an obvious one, especially for someone who is self-hosting an internet search engine (which has relatively high traffic, bandwidth and storage requirements) in his own home - once the AI bubble pops hardware prices come back down to where they were a few years ago and more and more people choose to self-host the current reasonably good open weights models (or more optimistically new hardware gets cheaper and better and new open weights models get smaller and better).
    • mono442 4 hours ago
      That's not exactly right. You pay to generate what you need once and after that it's fine to maintain the code by yourself without the ai.
      • a_cul 4 hours ago
        If you read the article he addresses this: highly optimized low-level code is already pushing the boundaries of what he's capable of understanding, so getting an LLM to generate said code would make it basically impossible to understand and maintain
        • dewey 1 hour ago
          > so getting an LLM to generate said code would make it basically impossible to understand and maintain

          This feels like something that was true 2 years ago, the current models (Opus 5.5 for example) in popular languages (My experience mostly with Go / Ruby) are so good that this doesn't feel true to me any more.

          Especially true on established code bases where there's lots of context available for the agent on how the architecture should look like.

      • rambambram 3 hours ago
        Please read the article.
    • adezxc 7 hours ago
      Sorry, but first I interpreted your sentence to be negative due to "red pill male comunities etc." but I guess you used it in the original connotation, in that case, I agree :D
      • wannabe44 3 hours ago
        Red pill is not necessarily political. It's just about understanding the world beyond what you're told.
      • Llamamoe 4 hours ago
        That's because 4chan and the manosphere ARE the main users of the phrase, which is ironic considering Matrix was written by two trans women and the pill was originally intended as a metaphor for transition.
    • orlysosiryes 6 hours ago
      [flagged]
      • jraph 6 hours ago
        That's no reason to add even more.

        Did you create your HN account to defend AI?

        • orlysosiryes 4 hours ago
          I don’t do “accounts”. I just create one to respond if I feel the need to.

          The copium and double standards in here are suffocating.

      • pjmlp 6 hours ago
        Yes, because there is only so much subscriptions a bank account can support.
  • hizlikovboy27 6 hours ago
    Financial dependence on AI is a truly difficult situation. Im currently going through the same thing myself. I think you made the right decision.
    • orlysosiryes 6 hours ago
      I think the author is overindexing on the difficulty of the code. Sure if you let AI do it, they have a knack of going deeper than you yourself could but then again you can ask to simplify and explain ad infinitum. The code you end up with can be as reasonable as you desire.

      No need to be worried about perpetual AI serfdom..

      • jraph 6 hours ago
        If one is to spend that much time to babysit the AI, they'd better write the code themself, it will be faster and cheaper.
        • orlysosiryes 4 hours ago
          It is faster to write thousands of lines of code rather than ask a few simple questions..?

          Dream on guys.

          • gimlichgu 4 hours ago
            i actually have a c script that can generate trillions of lines of codes with a single button press, id be peachy pleased to send that along your way if you are interested
          • Barrin92 2 hours ago
            >It is faster to write thousands of lines of code

            nobody who builds a small scale real world product people rely on is interested in maniacally churning out thousands of lines of code in short order, this is the "productivity crowd" of people who talk about their fifteen million tools who have somehow never shipped a single usable piece of software

            • equinumerous 1 hour ago
              Agree, code has never been the slow part for me, on any software project. Everything else is.
        • LtWorf 4 hours ago
          But then you need to work rather than doomscroll while you wait for the AI to do its thing!
          • orlysosiryes 4 hours ago
            “Work”? You mean spending all day toying with syntax and documentation?
            • xmcqdpt2 1 hour ago
              Isn’t syntax and documentation what we do as developers? The reason why an LLM can build applications quickly is that it has access to well thought out, stable libraries.
            • jraph 2 hours ago
              Why do you care about persuading us so much? Just go use your LLM and kill our jobs with your newly increased productivity already.

              Imagine all you could have achieved if you had prompted an LLM instead of creating accounts and writing comments here! I'm sorry for your opportunity loss btw.

  • theolivenbaum 8 hours ago
    At the risk of being one of those people shouting "but why not language X?", I'd suggest giving modern C# a serious look. Given the background in C++ and Java, it should feel fairly familiar, while being arguably much more expressive than either and offering excellent language and runtime support for writing allocation-free code.

    We've recently ported two large projects to C#, one from Java and another from C++, and seen performance improvements ranging from 30% to 300% faster, largely by focusing on eliminating allocations rather than doing anything particularly clever algorithmically.

    • Zambyte 8 hours ago
      > largely by focusing on eliminating allocations rather than doing anything particularly clever algorithmically.

      Did rewriting it in C# make this easier, or did rewriting make this easier?

      • theolivenbaum 6 hours ago
        I've of course not tried rewriting it in other languages, so take that with a grain of salt. But the code is by design required to stay aligned with the source codebases as the ports are continuously updated with upstream improvements, so I don't think the gains are coming from being a very different rewrite. What I see is just how much easier it is to express efficient code in c# without loosing expressiveness, with a really nice to use low level support (Span/ReadOnlySpan, stackalloc, built in intrinsics support, easy to use pooling, etc) so you can refactor where it matters.
        • lelanthran 5 hours ago
          I think GP was asking if the speedup was due to eliminating allocations (maybe by doing them upfront?), not if the expressiveness of efficient code is easy.
    • giancarlostoro 8 hours ago
      Outside of .NET itself, C# is one of those rare things Microsoft got disgustingly correct. It's entire runtime is cross-platform and MIT licensed.
      • rob74 1 hour ago
        You can probably blame both on Anders Hejlsberg (https://en.wikipedia.org/wiki/Anders_Hejlsberg), who started off with Turbo Pascal and Delphi (both still held in high regard) and then, after getting poached by Microsoft, where he (co-?) led the development of .NET, C# and then TypeScript.
      • whs 8 hours ago
        I was going to learn C# then I realize it's probably the only language that still has commercial, non domain specific paid library. (eg. Paid react component is fine for me, but a paid circuit breaker library is not)
        • pjmlp 6 hours ago
          Nah, C, C++, Java, Ada, PL/I, NEWP, COBOL, Fortran, RPG,.... have enough commercial libraries to chose from.
      • skydhash 7 hours ago
        > It's entire runtime is cross-platform and MIT licensed

        It does not run on OpenBSD. And I think it only got recently ported on FreeBSD. Yes, they are “small” platform, but lot of languages are there.

        • pjmlp 6 hours ago
          Also embedded, mainframes and micros.

          There is Meadows for embedded, and the oldie .NET Compact Framework, but it isn't the same regarding capabilities like real time processing.

      • pjmlp 6 hours ago
        Partially, if only the first AOT story wasn't like NGEN, and stuff like Span, and all the low-level improvements since C# 7 were already there in version 1.0.

        Unfortunately even today their Windows team keeps being quite dismissive, pushing C++ instead.

        Even the new Windows ML stuff has, yet again, better C++ and Python story than C# (WIP at the Ignite sessions time).

        Unlike how Apple uses Objective-C and Swift, or Google Java and Kotlin, managed runtimes have an hard upsell on Windows division.

        While Azure nowadays rather push open source projects in Go, Rust, Java than .NET.

        Yeah it is a great development stack, yet its own creator has some issues pushing its adoption even internally.

    • keyle 8 hours ago
      I'd claim this is the rewrite done by people that know what they're doing that is responsible for most of the gains vs. C#'s compiler to magically make things run faster.

      Sure the C# compiler is great and mature; and .NET Jit probably great too. But these massive gains can only be explained by "do less stoopid stuff".

      • theolivenbaum 6 hours ago
        That plus having a strong language that makes it easy to express safely efficient code. Most of the performance gains come from how easy it is to measure and refactor code where it matters without impacting readability, which is something that I find a lot more difficult with other programming languages, even in this era of AI.
    • HackerThemAll 1 hour ago
      If I was in charge of Java applications, I'd rewrite them all to C#, Rust, Zig, or even Golang which I don't praise, even if that meant for them to be slower than the original Java, only to escape the Oracle hell.
  • sylware 3 hours ago
    Until marginalia is noscript/basic HTML browser friendly in its usage and that with or without anonymous web APIs, I am more than glade to recommend it. It would be sad if it becomes gated by the web engines of the whatwg cartel (mojeek did fall not that long ago). They have to understand that the cartel and their friends may shadow-pay hackers to destroy them (you must not underestimate the toxicity of "Big Tech" and expect the worst here, those are seriously nasty and evil people). Don't forget, with a public online service, 90% of the time is keeping it safe and available (more at the beginning while you build your technical defence with the network/data centers operators).

    That said, if I have an advise to the devs for the long run: binary specifications. Those binary structures will be manipulated by many correct computer languages (bindings often required the higher the computer language is). It is a spectrum: some parts of those specifications may be very rigid (hardcore friendlyness with the hardware), others may be super flexible using a technically expensive component model, and ofc things would "move" back and forth between this rigidity and this flexibily because I don't think here they'll find a static 'sweet spot'. But being as much as possible independent from computer languages out there is worth the price (yep, you lose a good amount of comfort and development speed) on the long run.

  • nnevatie 7 hours ago
    > 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.

    • marginalia_nu 3 hours ago
      (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.

      • xmcqdpt2 1 hour ago
        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 1 hour ago
          Yeah the motiation for the port is still mostly ergonomics. Like it's worth it for std::span, <algorithm>, and TSan alone.
      • derinbay 1 hour ago
        [flagged]
    • trickypr 7 hours ago
      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.

      • cpgxiii 6 hours ago
        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 6 hours ago
          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.

      • Narishma 6 hours ago
        One place where it's definitely worse than C++ is memory usage.
        • marginalia_nu 2 hours ago
          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.
        • pjmlp 5 hours ago
          Depends in the C++ skills, and how the code looks like, from "C with a C++ compiler" up to "worthwhile of a CppCon talk".
    • pjmlp 6 hours ago
      It works great for Amazon and Netflix, some people can, others don't.
  • potato-peeler 7 hours ago
    > 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?

    • marginalia_nu 12 minutes ago
      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".

    • lelanthran 5 hours ago
      > 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-peeler 5 hours ago
        > 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?

        • lelanthran 4 hours ago
          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).

          • potato-peeler 4 hours ago
            > so if you think overthinking things is a good thing, then I guess I agree, because I did that too

            We are now brothers in arms :)

    • sph 6 hours ago
      “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 6 hours ago
        > 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...