clockworklabs / clockworklabs/SpacetimeDB

Investigate codegen for global state in rust bindings

Open
#681 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
25.2k
Forks
1.1k
Avg merge
2d 7h
Merged PRs (30d)
46

Description

Right now, in crates/bindings/src/lib.rs we cache a row buffer in a thread_local. A comment claims that this gets optimized away, but I don't see that happening. I see calls for getting and using the local key still that are definitely not inlined and definitely not optimized out.

Removing that overhead while providing a safe interface to the bindings just takes some doing. I think if we can require code using this buffer to not be reentrant, we can recover that promise of optimizing down to just a normal wasm global lookup, while still giving access to a &mut Vec reference. Other strategies may trade eg RefCell counting for ease of implementation. I haven't measured yet.

It probably isn't low hanging fruit yet. But as the new memory architecture comes online, I expect to see more of this sort of overhead show up.

cf https://github.com/clockworklabs/SpacetimeDB/pull/452/files

cc @gefjon

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 in crates/bindings/src/lib.rs and compare the current thread_local buffer handling with the linked pull request 452. Measure the overhead of local-key access and determine whether a safe non-reentrant approach or another strategy meets the optimization goal. Done means the overhead is measured and a concrete implementation direction is established.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, wasm
Domain
backend, performance
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.