Rust Async Working Group
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit
      • Invitee
      • No invitee
    • Publish Note

      Publish Note

      Everyone on the web can find and read all notes of this public team.
      Once published, notes can be searched and viewed by anyone online.
      See published notes
      Please check the box to agree to the Community Guidelines.
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Sharing URL Help
Menu
Options
Versions and GitHub Sync Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit
Invitee
No invitee
Publish Note

Publish Note

Everyone on the web can find and read all notes of this public team.
Once published, notes can be searched and viewed by anyone online.
See published notes
Please check the box to agree to the Community Guidelines.
Engagement control
Commenting
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Suggest edit
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
Import from Dropbox Google Drive Gist Clipboard
   owned this note    owned this note      
Published Linked with GitHub
1
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
# Deep dive: Design of async IO traits Link to document: https://github.com/nrc/portable-interoperable/blob/master/io-traits/README.md ###### tags: `deep-dive` Leave questions, observations, discussion topics below. --- ## Requirements eholk: "Traits should work well as trait objects" - After we have AFIDT, `dyn*`, etc., more things may be dyn-safe than they are now. If we rely on these features for async I/O trait objects, does that still satisfy this goal? nrc: People use trait objects a lot for I/O. They have to work well with dyn*. But if stuff can work without that, maybe that's better? eholk: So if it works well with trait objects but requires dyn* that satisfies the requirement. tmandry: "buffers should not be constrained to a single concrete type." – Is this in support of the goal below (allocated on the stack or owned by other data structures), or is there more to it? It seems like you could refine this requirement to another reason behind it. nrc: Today it's a mutable slice which is somewhat abstract (e.g. you can use a Vec or whatever). Antipattern is tokio's Bytes type, people hated that and wanted to use their own. Also don't want to assume that `Vec<u8>` is good enough. tmandry: Why do people want to use their own? Management of the lifetime. Others? nrc: Control over allocation. For example, you have a data structure that works with memory mapped files, or funky data structures like a rope (you could take a slice of components of it). --- ## Readiness read eholk: Would it make sense to add a builder API for `Interest` and `Readiness`? Right now it looks like we'd have a bunch of constants that can be ored together, but a higher level API would be nice. nrc: That was in a previous version, just haven't copied it over. --- ## Adapter types and downcasting tmandry: For adapter types, how "branchy" will they have to be to make use of `ReadyRead`/`OwnedRead` impls of the inner type? Is there an opportunity for the other versions to be optimized out? (If not should we just be using `dyn` for those?) tmandry: Can I implement the whole adapter type in the async fn, and does inline work there? nrc: To be a good citizen you should implement all three traits, and in the basic `Read` trait you'd write out the downcasting branches and use the better implementation. But maybe that's not worth it. Not sure how well it would get optimized out. tmandry: If we mark `as_ready` and `as_owned` as `inline(always)` we can optimize across compilation units. nrc: Only in the static case; not for dyn. Then you need some good LTO/devirtualization eholk: As long as you don't have a trait that's sometimes readiness or sometimes owned it should optimize fairly easily in the static case. --- ## Alternatives tmandry: Would like to discuss these more. In particular, there was one proposal that let you share an implementation between the three approaches (I think). Here you have multiple implementations. nrc: You're never going to get into an unexpected path; user has to opt-in to a specialized I/O model. Not going to opt in to both, only going to do 2 out of 3. Only adapters have to implement all 3. tmandry: Why 2 and not 1? nrc: One path which is optimal for your constraints if it's supported in the environment, and one that's slightly less optimal that's supported in all environments. tmandry: Ok so end user is writing an app that might run in different environments. nrc: Implementers also going to implement a couple. Tokio is going to focus on Readiness, Glommio might focus on Completion, for instance. nrc: Tokio's interesting since it's adding uring. Depending on the platform, Tokio may not offer the uring implementation. Trait impls would depend on OS. nrc: You also get the choice of saying you *only* support the completion system path. tmandry: Lots of adapter types right? nrc: Seems fairly common for e.g TLS. tmandry: So you might be writing three paths. Maybe that's better than writing one path that behaves differently depending on the environment. nrc: Goes back to question of whether to do the testing. Can only do testing at end user level. tmandry: Testing at end user level makes sense. Still have three paths. nrc: Adapter code would need to have paths for each approach and test those. eholk: The adapters just have to implement the three traits. Where it gets tricky with the downcasting.. nrc: Question is whether the adapter should do its own downcast testing in the `Read` implementation. It's reasonable to say no; we can have the end user do it if they care. I think this is right. An adapter should implement all three traits but not downcast. tmandry: End user of the Read trait might not be the application developer, could be a library like hyper. nrc: I think that's okay; they know which scenarios they want to be usable in. Hyper is doing network I/O so readiness is probably the right tradeoff. tmandry: I've seen completion IO in network environments but very specialized, not web servers, so I buy that. --- nrc: One buried question is about allocators. The `OwnedRead` trait only works with the default allocator. Imagine `<A>` on the `OwnedRead::read` method. The allocator gets used in the dynamic destructor. eholk: Not sure dyn* helps here. eholk: Could make the allocator a `dyn*` or trait object? eholk: Implement `From` for `Vec<_, dyn* Allocator>` nrc: How to convert from a normal Vec? nrc/ehok: `into_raw_parts` and then pass that into the new `Vec` type. Wildly unsafe tmandry: We could encapsulate as `Vec::with_dyn_allocator(Self)`. nrc: Has to allocate, might annoy some people. eholk: Many allocators are ZSTs. Should eventually be able to coerce ZSTs to dyn*. nrc: That would be cool. --- tmandry: Coming back to the "three paths" problem, I'm still a little concerned about most code being in adapters where you have three implementations. nrc: Problem with InternalRead is it requires you to decide which path to use in the implementation for that type. e.g. Socket doesn't know what the user's buffers look like. tmandry: Curious if there's much commonality between the implementations. More of an open research question. nrc: I think there's not a lot. For Readiness you have to do a two phase approach for there to be any point. OwnedRead and regular Read has some similarities, but not in a way that's easy to express in Rust. nrc: Suspect that the different implementations will be frustratingly similar, but not enough to write with a macro. tmandry: If we discover a macro approach it can exist in the ecosystem. ---

Import from clipboard

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lose their connection.

Create a note from template

Create a note from template

Oops...
This template is not available.
Upgrade
All
  • All
  • Team
No template found.

Create custom template

Upgrade

Delete template

Do you really want to delete this template?
Turn this template into a regular note and keep its content, versions, and comments.

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Forgot password

or

By clicking below, you agree to our terms of service.

Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
Wallet ( )
Connect another wallet

New to HackMD? Sign up

Help

  • English
  • 中文
  • Français
  • Deutsch
  • 日本語
  • Español
  • Català
  • Ελληνικά
  • Português
  • italiano
  • Türkçe
  • Русский
  • Nederlands
  • hrvatski jezik
  • język polski
  • Українська
  • हिन्दी
  • svenska
  • Esperanto
  • dansk

Documents

Tutorials

Book Mode Tutorial

Slide Mode Tutorial

Contacts

Facebook

Twitter

Discord

Feedback

Send us email

Resources

Releases

Pricing

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions and GitHub Sync
Upgrade to Prime Plan

  • Edit version name
  • Delete

revision author avatar     named on  

More Less

No updates to save
Compare with
    Choose a version
    No search result
    Version not found
Sign in to link this note to GitHub
Learn more
This note is not linked with GitHub
 

Feedback

Submission failed, please try again

Thanks for your support.

On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

Please give us some advice and help us improve HackMD.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

      Link with GitHub

      Please authorize HackMD on GitHub
      • Please sign in to GitHub and install the HackMD app on your GitHub repo.
      • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
      Learn more  Sign in to GitHub

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Include title and tags
      Available push count

      Upgrade

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Upgrade

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully