Skip to content

perf,fix(zero-solid): back to produce but pre-reading relationships and optimizing initial view build#3701

Merged
grgbkr merged 4 commits intomainfrom
grgbkr/mlaw-solid
Feb 4, 2025
Merged

perf,fix(zero-solid): back to produce but pre-reading relationships and optimizing initial view build#3701
grgbkr merged 4 commits intomainfrom
grgbkr/mlaw-solid

Conversation

@grgbkr
Copy link
Contributor

@grgbkr grgbkr commented Feb 4, 2025

The reconcile optimization approach (#3682) was incorrect (I misunderstood how reconcile works), as was revealed by the tests added here: #3692.

This approach goes back to using produce, but addresses the correctness issue by using an idea @tantaman came up with of reading the relationships of the changes at the time the push is received, but still queueing them to be applied to the solid store state on transaction completion. We are careful to only read relationships in the changes actually used by applyChanges.

This solved the correctness problem, but while much faster than the 30 seconds prior to us trying to optimize this, the 3000 row initial load case in hello-zero-solid was still spending ~742ms in SolidView#applyChanges.
Pasted Graphic 2

This is because the proxy used by solid produce is fairly slow. To address this, I added an optimization for the case where the store's view is currently empty. If the store is currently empty build up the view on a new plain old JS object root, which is returned for the new state. This avoids building up large views from scratch using solid produce. This brings the time for the 3000 row initial load case in hello-zero-solid to ~133ms.
Pasted Graphic 1

@grgbkr grgbkr requested review from arv and tantaman February 4, 2025 03:27
@vercel
Copy link

vercel bot commented Feb 4, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
replicache-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 4, 2025 3:29am
zbugs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 4, 2025 3:29am

@github-actions
Copy link

github-actions bot commented Feb 4, 2025

🐰 Bencher Report

Branchgrgbkr/mlaw-solid
Testbedlocalhost
Click to view all benchmark results
BenchmarkFile SizeBenchmark Result
kilobytes (KB)
(Result Δ%)
Upper Boundary
kilobytes (KB)
(Limit %)
zero-package.tgz📈 view plot
🚷 view threshold
930.59
(+0.13%)
947.93
(98.17%)
zero.js📈 view plot
🚷 view threshold
175.26
(0.00%)
178.77
(98.04%)
zero.js.br📈 view plot
🚷 view threshold
48.82
(-0.06%)
49.83
(97.98%)
🐰 View full continuous benchmarking report in Bencher

@github-actions
Copy link

github-actions bot commented Feb 4, 2025

🐰 Bencher Report

Branchgrgbkr/mlaw-solid
Testbedlocalhost
Click to view all benchmark results
BenchmarkThroughputBenchmark Result
operations / second (ops/s)
(Result Δ%)
Lower Boundary
operations / second (ops/s)
(Limit %)
src/client/zero.bench.ts > basics > All 1000 rows x 10 columns (numbers)📈 view plot
🚷 view threshold
73.50
(+0.55%)
68.31
(92.94%)
src/client/zero.bench.ts > with filter > Lower rows 500 x 10 columns (numbers)📈 view plot
🚷 view threshold
90.61
(-4.35%)
90.28
(99.63%)
🐰 View full continuous benchmarking report in Bencher

* `EditChange#node` and `EditChange#oldNode`. The `ViewChange` type
* documents and enforces this via the type system.
*/
export type ViewChange =
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't love having these new types exposed in @rocicorp/zero/advanced, but it seemed better than just dropping the relationships from ChildChange and EditChange.

@grgbkr grgbkr merged commit 4a36a5b into main Feb 4, 2025
11 checks passed
@grgbkr grgbkr deleted the grgbkr/mlaw-solid branch February 4, 2025 03:50
function materializeNodesRelationships(node: Node): Node {
return {
row: node.row,
relationships: Object.fromEntries(
Copy link
Contributor

@arv arv Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need all these temporary arrays?

I'm worried about the strain we are putting on the GC here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Further optimized this here: #3702

Copy link
Contributor

@arv arv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

I still don't feel good about this. Why is it so slow?

@aboodman
Copy link
Contributor

aboodman commented Feb 4, 2025 via email

@aboodman
Copy link
Contributor

aboodman commented Feb 4, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants