component-model icon indicating copy to clipboard operation
component-model copied to clipboard

Idea: cheap trivial streams / futures

Open lann opened this issue 4 months ago • 3 comments

(post-0.3.0)

Currently we use option<stream<...>> (e.g. here) to avoid stream bookkeeping for empty streams (iirc).

As an alternative, how about a stream.empty built-in that returns a "pre-dropped" readable stream? This would be semantically equivalent to stream.new + stream.drop-writable.

A little more complicated but potentially even more useful would be a future.resolved, acting like future.new + future.write. There are a lot of future<result<...>> return types that could benefit from being able to return future.resolved(err(...)).

lann avatar Aug 20 '25 15:08 lann

Good ideas and thanks for filing! I've also wondered about the same thing. If we can find real workloads where it's a speedup to have these sorts of "fused" built-ins, I think it'd make sense to add them.

lukewagner avatar Aug 20 '25 16:08 lukewagner

I guess I'm seeing option<stream<...>> as evidence that someone at least thinks that its worth avoiding an extra stream allocation. 🙂

lann avatar Aug 20 '25 18:08 lann

Assuming there's no semantic distinction between none and an empty stream, I suppose there's also an ergonomic advantage with option<stream<...>> since, depending on the bindings, it's easier to pass nothing than to figure out how to conjure an empty stream.

lukewagner avatar Aug 20 '25 18:08 lukewagner