News for hackers. Stuff that matters.
Re:Rust: Dropping heavy things in another thread can make yo... by rcxdude on Saturday May 30, 2020 @05:31PM (#23364944)
Deallocation at the end of a program's execution can substantially add to its runtime, and it's entirely waste. It's a much more common strategy than you might think.
Re:Rust: Dropping heavy things in another thread can make yo... by pdimitar on Saturday May 30, 2020 @05:37PM (#23364990)
You are right, I indeed didn't know it was that common.

But still, in a world where languages and runtimes are also judged by their ability to run in lambda/serverless setups, I'd think this practice will start being obsolete, wouldn't you think?

(What I mean is that I imagine that any serverless function that runs in severely constrained and measured environments like the AWS Lambda would gain a significant edge over the competition if it did an eager cleanup. Should allow more of them to work in parallel?)

Re:Rust: Dropping heavy things in another thread can make yo... by setr on Saturday May 30, 2020 @07:32PM (#23365793)
I don't understand; a lambda function executes and closes, and any leak gets handled by lambda runtime (by freeing the whole lambda function)-- exactly the same as running a cli tool. It seems to me that the server-less context is actually exactly where you'd employ this strategy: the programs by definition cannot be long-lived, so unless they generate so much garbage as to oom in that timeline, there is no need to deallocate anything yourself.

The leak to watch out for is reduced to the persisted data (eg in S3) between executions

Re:Rust: Dropping heavy things in another thread can make yo... by pdimitar on Saturday May 30, 2020 @07:49PM (#23365903)
Yeah, this is what I was saying -- that it could produce too much garbage if no manual free-ing of memory is done.

I suppose, judging by the downvotes, that some find that perspective naive so I'll just cut it here because no productive discussion is happening. :(

Re:Rust: Dropping heavy things in another thread can make yo... by setr on Sunday May 31, 2020 @10:31AM (#23369796)
the purpose/pattern is to ignore deallocation when the program finishes -- not during runtime. If you have 30MB of space, and your program will only ever use 20MB, why bother?

You only need to care when you're at risk of OOM'ing during runtime. If you're generating too much garbage, you either need to start cleaning up after yourself, or you need to generate less of it -- but it doesn't matter which choice you take from the perspective of the OS or the server-less function.

The only reason I can think of for server-less to impact the validity of this pattern is from it's lower memory capacity -- but otherwise it's the same constraints. And anyways, it's probably not nice to generate a few GB of garbage even if the user has the space

Re:Rust: Dropping heavy things in another thread can make yo... by folmar on Saturday May 30, 2020 @06:21PM (#23365315)
Most compiler are not designed to run in daemon mode, specifically it's non-issue since their startup is normally fast. And the compiler and runtime are a different thing.
Re:Rust: Dropping heavy things in another thread can make yo... by pdimitar on Saturday May 30, 2020 @06:26PM (#23365357)
I realise that, but nowadays language servers are a pretty normal practice in no small amount of areas.
Re:Rust: Dropping heavy things in another thread can make yo... by smabie on Saturday May 30, 2020 @09:48PM (#23366522)
You mean like LSP? Why would a compiler and a language server be integrated in the first place? Clearly a LSP server wouldn't use a no-freeing strategy, but there's no reason why it would cause issue with a compiler. A compiler must terminate, assuming parsing isn't turing complete (like Perl) and that the source code is finite. This is why it's okay for it to leak memory.
Re:Rust: Dropping heavy things in another thread can make yo... by steveklabnik on Sunday May 31, 2020 @09:07AM (#23369331)
> Why would a compiler and a language server be integrated in the first place?

Because a language server needs to do a lot of the same work as a compiler.

This is an eventual hope for rustc. For now, the latest language server and it share a bunch of libraries, but language servers are effectively compiler frontends.

Re:Rust: Dropping heavy things in another thread can make yo... by pdimitar on Sunday May 31, 2020 @08:23AM (#23369099)
Yep, I guess I conflated compilers and LSP. I imagined compilers would have daemon modes. Seems like I was wrong.