Skip to content

unsync / non-thread safe version #200

@stbuehler

Description

@stbuehler

Hi,

I'm working on a small webserver; now that we have the current_thread runtime in tokio it seems interesting to write thread-local async code.

This would allow us to use "unsync" versions of Bytes and BytesMut; the idea was raised in #99 before.

The overhead is in the atomic operations; thread-local versions can use a simple ref_count: usize, and also don't need to worry about concurrent calls of shallow_clone (although by making Bytes and BytesMut !Sync that could be avoided too; they'd still be Send).

I have a work-in-progress fork at https://github.com/stbuehler/bytes/tree/unsync if someone wants to try running a few benchmarks (I basically reimplemented it from scratch, without original_capacity. I also added a UnBytesExt variant that defaults to extending the allocation).

In the existing benchmarks the "unsync" version wins on my system mostly the split_off_and_drop case (#118 might help the "sync" version on that), and some small improvements for drain_write_drain, fmt_write and from_long_slice - but loses in defer_* and slice_* (and I have no idea why; in disassemble dumps it looks like the compiler favors the inline branch in the "sync" part but not in the "unsync" part; exported as_ref wrappers looked exactly the same otherwise).

It would also be possible to put a shared reference to a "sync" Inner into the "unsync" Shared, so the "unsync" types could also refer to storage shared between threads on demand.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions