typst / typst/ecow

Proposal: Make `EcoVec` single-threaded by default for better performance

Open
#69 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
320
Forks
32
Avg merge
4d 13h
Merged PRs (30d)
1

Description

Context

Currently, EcoVec uses an AtomicUsize in its Header to track reference counts unconditionally. This makes EcoVec thread-safe (Send/Sync), but it incurs a performance overhead due to atomic instructions (fetch_add/fetch_sub) and cache synchronization, even when used in entirely single-threaded contexts.

With the eventual support for custom Allocators - assuming we will be mirroring Vec's decision - EcoVec will be able to be used with stateful local allocators (like bump or arena allocators) that are themselves also single-threaded (!Send/!Sync). Forcing an atomic reference count on the collection in these scenarios is wasteful.

Proposal

I propose making EcoVec single-threaded by default to maximize performance for standard workloads, while still supporting multi-threaded contexts. We could achieve this by, for example, gating the atomic features via a Cargo feature (such as sync) or by splitting into two distinct types. I'd suggest the former.

Impact

For instances such as single-threaded layout engines, parsers, or single-threaded compiler stages, replacing atomic operations with raw Cell mutations will remove memory synchronization overhead and unlock significant performance improvements during cloning and dropping.

I'd love to hear the maintainers' thoughts on which architecture fits the project's direction best.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by inspecting EcoVec’s Header, which currently uses AtomicUsize, and trace the clone and drop reference-count operations. Check how the current implementation provides Send and Sync, then clarify the intended architecture with maintainers. Done means EcoVec is single-threaded by default while multi-threaded use remains supported through an agreed design.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.