Skip to content

Commit d856043

Browse files
committed
feat: perfomance subsection to motivation
1 parent 1ebf5b1 commit d856043

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

text/0000-forget-marker-trait.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,13 @@ The async version of [`take_mut`] cannot be created as it relies on cleanup code
246246

247247
[`take_mut`]: https://docs.rs/take_mut/latest/take_mut/
248248

249+
### Performance
250+
251+
As we saw earlier, `async` code is forced into `'static` bounds on any non-trivial task such as spawning or sending messages between tasks. That way, references cannot be used, and users must fall back into `Arc` or owned types. `Arc` will [ping-pong] cache line with the counter between the cores, while owned types enforce unnecessary allocations and clones. Example would be a [rumqttc `publish`] which takes `topic` as `Into<String>`. Why? Because it sends this topic to another task. If `!Forget` types were available, a better API choice would be to make the `Future` returned by `publish` be `!Forget` and wait until another task formats the `topic` into the output buffer and reports either success or failure of the publish.
252+
253+
[ping-pong]: https://assets.bitbashing.io/papers/concurrency-primer.pdf
254+
[rumqttc `publish`]: https://docs.rs/rumqttc/latest/rumqttc/struct.Client.html#method.publish
255+
249256
### C/C++ bindings + async do not work well together
250257
[example-async-c-cpp-bindings]: #example-async-c-cpp-bindings
251258

0 commit comments

Comments
 (0)