• CanadaPlus@lemmy.sdf.org
        link
        fedilink
        arrow-up
        10
        ·
        1 year ago

        That sounds pretty great. My impression is that relatively little code actually runs that often.

        but with none of the footguns of manual memory management, no garbage collection pauses, but yet also no evil stepparent style borrow checker to be beaten by.

        That part sounds implausible, though. What kind of memory management are they doing?

          • CanadaPlus@lemmy.sdf.org
            link
            fedilink
            arrow-up
            11
            arrow-down
            1
            ·
            1 year ago

            Oh, you just mean it’s a kind of garbage collection that’s lighter on pauses. Sorry, I’ve had the “my pre-Rust pet language already does what Rust does” conversation on here too many times.

            • BatmanAoD@programming.dev
              link
              fedilink
              arrow-up
              8
              ·
              1 year ago

              To be fair, the drop/dealloc “pause” is very different from what people usually mean when they say “garbage collection pause”, i.e. stop-the-world (…or at least a slice of the world).

              • CanadaPlus@lemmy.sdf.org
                link
                fedilink
                arrow-up
                2
                arrow-down
                1
                ·
                1 year ago

                Yeah, it might be better, I don’t actually know. It’s not as novel as OP maybe thinks it is, though.

                • BatmanAoD@programming.dev
                  link
                  fedilink
                  arrow-up
                  4
                  ·
                  1 year ago

                  That’s fair; Python, Swift, and most Lisps all use or have previously used reference-counting. But the quoted sentence isn’t wrong, since it said no “garbage collection pauses” rather than “garbage collection.”

            • Ethan@programming.dev
              link
              fedilink
              English
              arrow-up
              3
              ·
              1 year ago

              Garbage collection is analyzing the heap and figuring out what can be collected. Reference counting requires the code to increment or decrement a counter and frees memory when the counter hits zero. They’re fundamentally different approaches. Also reference counting isn’t necessarily automatic, Objective-C had manual reference counting since day one.

              • BatmanAoD@programming.dev
                link
                fedilink
                arrow-up
                6
                ·
                1 year ago

                “Garbage collection” is ambiguous, actually; reference counting is traditionally considered a kind of “garbage collection”. The type you’re thinking of is called “tracing garbage collection,” but the term “garbage collection” is often used to specifically mean “tracing garbage collection.”

              • CanadaPlus@lemmy.sdf.org
                link
                fedilink
                arrow-up
                3
                ·
                1 year ago

                It’s still mentioned as one of the main approaches to garbage collection in the garbage collection Wikipedia article.

                • Ethan@programming.dev
                  link
                  fedilink
                  English
                  arrow-up
                  1
                  ·
                  1 year ago

                  Ok, I concede the point, “garbage collection” technically includes reference counting. However the practical point remains - reference counting doesn’t come with the same performance penalties as ‘normal’ garbage collection. It has essentially the same performance characteristics of manual memory management because that’s essentially what it’s doing.

                  • CanadaPlus@lemmy.sdf.org
                    link
                    fedilink
                    arrow-up
                    2
                    ·
                    edit-2
                    1 year ago

                    That may well be. I’d say I understand the basic concepts, but people in this thread have more detail on the specifics and how they work out in practice than me.

                    It does make me wonder why everyone hasn’t been doing it, if there’s no drawbacks, though.

              • calcopiritus@lemmy.world
                link
                fedilink
                arrow-up
                6
                ·
                1 year ago

                There is no reference counting if the count is always one.

                The defining feature of reference counting is that its a runtime check. Which in turn results in a runtime performance.

                If there is no in memory counter at runtime, nobody calls that reference counting.

                  • calcopiritus@lemmy.world
                    link
                    fedilink
                    arrow-up
                    3
                    ·
                    1 year ago

                    I don’t know whatever that language is doing is called, but it’s not reference counting. It’s doing some kind of static code analysis, and then it falls back to reference counting.

                    If you call that reference counting, what stops you from calling garbage collectors reference counting too? They certainly count references! Is the stack a reference count too? It keeps track of all the data in a stack frame, some of it might be references!

                  • calcopiritus@lemmy.world
                    link
                    fedilink
                    arrow-up
                    3
                    ·
                    1 year ago

                    I don’t know what you read on my reply. But your reply makes no sense.

                    Let me rephrase it if you prefer:

                    Claiming that Rusty’s borrow checker is reference counting is hugely misleading. Since the borrow checker was made specifically to prevent the runtime cost of garbage collection and reference counting while still being safe.

                    To anyone unaware, it may read as “rust uses reference counting to avoid reference counting, but they just call it borrow checking”. Which is objectively false, since rust’s solution doesn’t require counting references at runtime.

                    I don’t know what mutable string or any of the other rant has to do with reference counting. Looks like you’re just looking to catch a “rust evangelist” in some kind of trap. Without even reading what I said.

              • CanadaPlus@lemmy.sdf.org
                link
                fedilink
                arrow-up
                5
                ·
                edit-2
                1 year ago

                Did you think rust doesn’t free up memory for you? That would be the biggest memory leak in history! No! Rust does reference counting, it just makes sure that that number is always one! What did you think the borrow checker was for?

                There is no runtime garbage collection in Rust. Given a legal program, it can detect where free-type instructions are needed at compile time, and adds them. From there on it works like C, but with no memory leaks or errors because machines are good at being exactly correct. If you want to say that’s just a reference counting algorithm that’s so simple it’s not there, sure, I guess you can do that.

                Roc has runtime overhead to do garbage collection, it says so right on their own page. It might be a post-Rust language but this feels like the same conversation I’ve had about D and… I can’t even remember now. Maybe Roc is a cool, innovative language. It’s new to me. But, it doesn’t sound like it’s doing anything fundamentally new on that specific part.

                Edit: Reading your follow up to the other person, it sounds like it has both a Rust-style compile time algorithm of some sort, and then (reference count-based) garbage collection at run time for parts of the program that would just be illegal in Rust.

                  • CanadaPlus@lemmy.sdf.org
                    link
                    fedilink
                    arrow-up
                    3
                    ·
                    edit-2
                    1 year ago

                    Just in case you missed it, that was unsafe rust that lacks the overheads.

                    It says some overheads. It’s different overheads, because Rust does not have reference counting garbage collection, even when safe.

                    Either you should go back and read what I said about reference counting being a runtime garbage collecting algorithm, or I think we’re just done. Why say more if it’s ignored anyway?

                    I don’t think I’m the zealot here.

          • Frezik@lemmy.blahaj.zone
            link
            fedilink
            arrow-up
            4
            ·
            1 year ago

            I wish more languages used ref counting. Yes, it has problems with memory cycles, but it’s also predictable and fast. Works really well with immutable data.

              • Frezik@lemmy.blahaj.zone
                link
                fedilink
                English
                arrow-up
                2
                ·
                1 year ago

                Thanks, this looks really interesting. I’ve thought for a while that Rust’s borrow checker wouldn’t be such a pain in the ass if the APIs were developed with immutable data in mind. It’s not something you can easily slap on, because the whole ecosystem fights against it. Looks like Roc is taking that idea and running with it.

    • Lena@gregtech.euOP
      link
      fedilink
      English
      arrow-up
      14
      ·
      1 year ago

      Yeah, I think Go’s compiler is so fast partially because it doesn’t use LLVM