Skip to content

Commit d290f57

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

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
@@ -270,6 +270,13 @@ unsafe { std::mem::forget_unchecked(borrower) };
270270
let first_byte = resource[0]; // Potential UB
271271
```
272272

273+
### Performance
274+
275+
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.
276+
277+
[ping-pong]: https://assets.bitbashing.io/papers/concurrency-primer.pdf
278+
[rumqttc `publish`]: https://docs.rs/rumqttc/latest/rumqttc/struct.Client.html#method.publish
279+
273280
## Relation between `Forget` and `Pin`
274281
[connection-to-pin]: #connection-to-pin
275282

0 commit comments

Comments
 (0)