clockworklabs / clockworklabs/SpacetimeDB
PERFORMANCE FIX: TableCacheImpl TODO: this just scans the whole table; we should build proper index structures
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 25.2k
- Forks
- 1.1k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 46
Description
It shows up in all my performance profiling as an issue. Specifically, the todo comment you guys have in there. Please prioritise, it is showing up in all my performance profiles.
crates/bindings-typescript/src/sdk/table_cache.ts
Class: TableCacheImpl
Method: #makeReadonlyIndex (private), around line 105
TODO: // TODO: this just scans the whole table; we should build proper index structures
Hot path: find() on unique indexes loops self.iter() and calls deepEqual(getKey(row), expected) per row (lines ~198–204)
filter() on ranged indexes does the same scan + deepEqual in matchRange
crates/bindings-typescript/src/lib/util.ts
Function: deepEqual (lines ~9–37)
Uses Object.keys() twice + recursive comparison
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 by reading crates/bindings-typescript/src/sdk/table_cache.ts, especially TableCacheImpl, #makeReadonlyIndex, find(), and filter(), then inspect deepEqual in crates/bindings-typescript/src/lib/util.ts. Trace how unique and ranged indexes currently scan rows and compare keys. Done means find() and filter() use proper index structures instead of scanning the whole table, with profiling confirming the hot-path improvement.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- databases, performance
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100