clockworklabs / clockworklabs/SpacetimeDB
Investigate codegen for global state in rust bindings
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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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