HNHacker News
TopNewBestAskShowJobs

rklaehn

1,071 karma · joined October 16, 2017

submissionscomments
rklaehn··on What Will the World Look Like with Less Babies?
What's surprising about people having less kids if the prevailing ideology in the west since many decades is basically malthusianism?

People are getting told from an early age that humans are a pest and that the world would be better off without them.

rklaehn··on Local async executors and why they should be the default
Which panics if you don't call it in the right context. So now you have code which can only be used under certain circumstances and with one particular async runtime.

Since when has it become acceptable in rust to have fns that just panic depending on the state of some thread local? That is one thing I really dislike about tokio.

The thread local runtime is convenience over correctness, which is antithetical to what rust usually favours.

rklaehn··on Local async executors and why they should be the default
You don't get weird higher-ranked lifetime errors when you use non Sync futures with hand-rolled async traits.

I am not saying that this is the reason to use local futures. But if you have decided that local futures are the way to go anyway, it's a nice benefit.

rklaehn··on Local async executors and why they should be the default
Automatic memory management is not exclusively positive, even if you don't care about performance.

If you lose deterministic destructors and therefore the possibility of RAII, for me it is a loss.

I worked with lots of garbage collected languages (Java, C#, Scala) before rust, and I don't miss garbage collection at all...

rklaehn··on Local async executors and why they should be the default
Kind of agree. The erlang runtime just gives you a process abstraction that is extremely cheap. So within a process you can do things logically sequentially without dragging the system as a whole down.

This approach would not have been the right choice for rust itself, since rust as a systems programming language can not have a runtime.

But there is a fun project called lunatic that implements a lightweight runtime in rust https://docs.rs/lunatic-runtime/latest/lunatic_runtime/ and then allows you to write lightweight processes for this runtime also in rust https://docs.rs/lunatic/latest/lunatic/

It seems heavily inspired by the actor model and erlang.

rklaehn··on Local async executors and why they should be the default
I think this blog post by tomaka gives a good summary of the current issues with async rust. Certainly much more comprehensive than what you can write in a hacker news post:

https://tomaka.medium.com/a-look-back-at-asynchronous-rust-d...

It highlights some of the same problems:

- “Just spawn a new task”

- The Send trait isn’t what it means anymore

rklaehn··on Local async executors and why they should be the default
Indeed.

That means that the interop story for golang is horrible. Golang can somewha work with libraries with C bindings. But you can not publish a golang lib as a lib.so with C bindings because of the runtime.

rklaehn··on Local async executors and why they should be the default
I fully agree that the async story needs attention.

Something as drastic as backwards-incompatible changes might not be needed.

But definitely much more documentation about best practices, highlighting the option of local async tasks, making the APIs for that more convenient, and also some low hanging fruits in terms of language syntax.

It seems a bit like while there was a lot of excitement about the async syntax a few years ago, now there is a MVP syntax and everything has just slowed down a lot.

rklaehn··on Local async executors and why they should be the default
If you use rust async with a local executor such as the tokio current thread runtime, it provides lightweight cooperative concurrency.

There is nothing ever happening at the same time, since you are on a single thread. That is why you don't need synchronization primitives such as Mutex but can live with something lightweight like RefCell. And that is why you can get by with non atomic reference counting smart pointers (Rc instead of Arc).

And it is cooperative in that you have to yield by calling await, otherwise nothing else will run.

What the article argues is that the option concurrent but not parallel, which both tokio and futures support in principle, should be advertised more and maybe even be the default.

rklaehn··on Local async executors and why they should be the default
It's not always that simple. What if your sync lib has some callbacks, and you want to do something in the callbacks that requires async.

You could argue that this mismatch exists even with rust itself, where you have Drop, which is sync, and you might have to do something in your drop that requires async, like closing a network connection.

You have to pass in some runtime handle that you can use to spawn a task to do what you have to do. This is definitely not simple and beginner friendly. Or even worse - say goodbye to RAII and tell people that they have to explicitly call an async shutdown fn.

rklaehn··on Local async executors and why they should be the default
Let's say you are using a low level networking library that is async to the core, like hyper or quinn.

Then you will have some ugliness at the boundary. You might get by with just spawning a current thread runtime to use your async lib, or do something like blocking channels if your low level library spawns long lived tasks.

If your low level libraries are all sync, then there won't be much ugliness.

rklaehn··on Local async executors and why they should be the default
There is quite some support for the second option. But it is not advertised at all.

E.g. there is an entire local task pool impl in tokio_util, but it is not enabled by default and at least for me was difficult to find. https://docs.rs/tokio-util/latest/tokio_util/task/struct.Loc...

I wrote an entire local executor pool before finding that thing and ripping my code out again...

At the very least the support for tasks for non-Send futures should be advertized more, and maybe also the APIs polished a bit.

rklaehn··on Local async executors and why they should be the default
Look at the extremely popular async_trait macro crate: https://crates.io/crates/async-trait .

What it does under the hood is to box everything. See https://github.com/dtolnay/async-trait#explanation

You would think that you should be able to desugar async traits to something that does not need to box. But this is not possible with stable rust.

There is an effort to make this possible. See for example this discussion here: https://blog.rust-lang.org/inside-rust/2022/11/17/async-fn-i...

Initially it was thought that Send bounds would not be needed, but community feedback strongly suggests that Send is indeed needed.

https://blog.rust-lang.org/inside-rust/2023/05/03/stabilizin...

All this is a real problem, and not just a "you are holding it wrong" problem.

Edit: here is the - still open - issue about higher-ranked lifetime errors: https://github.com/rust-lang/rust/issues/102211

rklaehn··on Local async executors and why they should be the default
Not sure what you mean by "returning a rust promise". But yes, Arc<Mutex<...>> is a thread safe smart pointer containing a mutex, which has quite some overhead.

You will see this in many places in the internals of async code that has to be Send.

OK in many cases, but it can kill you if you have to go through this for many small operations.

rklaehn··on Local async executors and why they should be the default
It's OK but not great.

Ideally library authors should provide a sync facade so people don't have to deal with this, like reqwest does.

rklaehn··on Local async executors and why they should be the default
I can see where you are coming from. But you can do most things purely in sync rust.

There are sync rust multithreading libs like rayon that are a joy to use, and there are even blocking versions of popular http libraries like reqwest: https://docs.rs/reqwest/latest/reqwest/blocking/index.html

They are usually doing some ugly stuff internally to make this work, but as a pure library user you don't have to care.

If you want to write something small that e.g. pulls some data via http, performs some computation, then pushes the result, it is totally possible to do this fully in sync rust.

And if you are writing a highly concurrent web server, looking into async might not be the worst idea.

rklaehn··on Local async executors and why they should be the default
Anecdotal evidence, but many large rust async code bases perform significantly better if you are using a single threaded runtime vs. a multithreaded runtime.

Here is an issue for the quinn crate that implements QUIC: https://github.com/quinn-rs/quinn/issues/1433

We have had very similar experiences when developing https://github.com/n0-computer/iroh

And this is with quinn still carrying around the synchronization primitives to make everything Send.

Another piece of anecdotal evidence: the functional collection library https://github.com/bodil/im-rs comes in two flavours: one using Arc and one using Rc. The reason for this is that you get a significant performance increase by using Rc (where manipulating the refcount is just an integer inc/dec) vs Arc where manipulating the refcount needs to be an atomic op.

Last but not least - often making futures Send requires you to box your futures. Send and lifetimes just does not play well together. Do something like this:

  trait Foo {
    type OpFut<'a>: Future<Output = ()> + 'a;
    fn op(&self) -> Self::OpFut<'_>
  }
This is what eventually you would want something like async_trait to desugar to. Use the above in a Send context, and you get a completely undecipherable higher-ranked lifetime error. So you are back to boxing all futures.
rklaehn··on Local async executors and why they should be the default
Multi threading and concurrency are not the same. You can have a very high performance server that handles thousands of requests concurrently on a single thread. That's how node/deno do things.

But the way to do things in async rust is that if you want concurrency you also have to use multithreading. At least that is what you see in all the examples and docs.

As soon as you require your futures to be Send you have to use not just concurrency but full blown multithreading primitives.

So e.g. you have to use Arc<RwLock<...>> where a Rc<RefCell<...>> would suffice.

Now, to be fair, both futures and tokio support local futures. There is boxed_local (https://docs.rs/futures/latest/futures/future/trait.FutureEx...) and tokio-util even comes with an optional local task pool (https://docs.rs/tokio-util/latest/tokio_util/task/struct.Loc...).

But these features are hidden and certainly not promoted in examples and documentation.

rklaehn··on Local async executors and why they should be the default
I think rust does it right in many cases. Raw rust multithreading is a pleasure to use, and some libraries like rayon are extremely unobtrusive.

That is why I am somewhat unhappy with the state of async rust. It does not yet have the quality and unobtrusiveness of sync rust libraries like rayon.

rklaehn··on Local async executors and why they should be the default
Yeah, it is old. But I only found it recently and did not see a discussion of it yet.

I found this quite interesting. I love rust, but async rust always seems almost like a different language.

Lifetimes become much more complex and much less useful, you use Box and Arc way too much. It seems like you would be better off if everything was heap allocated.

Working with local futures brings back some of the things I love about rust, but it is certainly not prominently featured in libraries like tokio and the entire async ecosystem.

rklaehn··on Ask HN: Why does every package+module system become a Rube Goldberg machine?
I find cargo (rust package manager) relatively pleasant to use. It's not perfect, but it also is not a constant source of confusion like sbt (scala package manger) was back when I did scala.

In the long term, I think the whole notion of a "package" is obsolete. In unison https://www.unison-lang.org/ , code is just a content-addressed merkle tree. So dependencies are both more precise and more fine grained than packages.

E.g. if there is a new version of a library, but the part of the library that you actually use is unchanged, unison will detect this and not trigger a full rebuild.

The whole notion of a package becomes less important.

rklaehn··on ‘Gold hydrogen’ is an untapped resource in depleted oil wells
I don't get the strong opposition to it. Yes, CO2 is a byproduct. And yes, that CO2 might leak out of the wells. But it would still be much better than the status quo, which is hydrogen from fossil fuels, with the CO2 being emitted 100%.

Hydrogen is very much needed for chemical synthesis (ammonia for fertiliser), and can also be used to make steel. Using this would be much better than blue hydrogen. A good pragmatic solution until we have green hydrogen.

rklaehn··on Generative AI profits off your code. Make them pay for it
This is a very clear cut case of a copyright violation by github copilot:

https://twitter.com/docsparse/status/1581461734665367554?lan...

In this instance the weights of the AI system just contain an obfuscated copy of the original source code.

rklaehn··on Generative AI profits off your code. Make them pay for it
In some cases the model will spit out verbatim copies of code. E.g. https://twitter.com/docsparse/status/1581461734665367554?lan...

So in this case the weights are not even a derivative work but just a compressed copy of the original code.

rklaehn··on Generative AI profits off your code. Make them pay for it
But if the AI has been trained on open source licensed code and occasionally can produce verbatim copies of said code, shouldn't the weights of the AI then also become open source under the same license?

You could argue that training is a form of compilation, and the weights are a derivative work.

rklaehn··on Berty: Privacy-first messaging app
We will reach out to you once we think iroh is usable enough for your use case.

Not before.

rklaehn··on Generative AI profits off your code. Make them pay for it
Interesting.

I would be fine with an AI being trained on my code, provided that the weights of said AI would then be published under the same license as my code.

Is there a license for that?

rklaehn··on Berty: Privacy-first messaging app
I am working on iroh, a rust implementation of ipfs.

I have to say that while this dismissal is shallow, it is ...not entirely incorrect... . There is certainly a lot of room for improvement in the current state of ipfs.

We would love to change your mind about ipfs performance and reliability. Once we got a version of iroh that is ready for production, we would be quite happy to let you try it out and get your feedback.

As far as I can see there is no fundamental reason why a set of protocols for content-addressed storage like ipfs can not be fast and reliable.

rklaehn··on Ask HN: What is the most impactful thing you've built?
I helped build the mission planning system for several earth observation missions, most notably the TerraSAR-X / TanDEM-X SAR mission. It has created the best global digital elevation map (DEM), surpassing the SRTM data set.

https://en.wikipedia.org/wiki/TanDEM-X

We were a tiny team of 2 core people. I was the main software engineer, the other main contributor was a mathematician.

The project was done in C#, but in a very functional style. I had to write my own functional collections library for it. Functional style was a very good fit for this kind of classical optimisation problem. Basically zero cost backtracking.

The planning system was very challenging because the two sats fly in close formation, and some operations can cause permanent damage.

I have since left the European space industry out of frustration that most interesting stuff seems to happen in the US, where I am not allowed to work due to ITAR.

rklaehn··on Iroh: A New Implementation of IPFS
In theory, you would create an IPNS entry for the root of wikipedia, then update that on each change. Wikipedia is a relatively static data set, so on a day probably much less than 1% gets changed.

So the new wikipedia tree reuses the vast majority of the previous version.

← PreviousPage 5 of 10Next →