-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
View Backend v2! #669
Closed
Closed
View Backend v2! #669
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Copy pasted from https://github.com/lukechu10/sycamore-web2
Will add it back later
lukechu10
added
C-enhancement
Category: new feature or improvement to existing feature
BREAKING CHANGE
Breaking changes introduced in this PR
A-SSR
Area: Server Side Rendering (SSR) and Static Site Generation (SSG)
labels
Apr 3, 2024
lukechu10
added
performance
Performance related
and removed
performance
Performance related
labels
Apr 4, 2024
Benchmark Report
@@ Performance Diff @@
## | wasm-bindgen | baseline | update | diff ##
#######################################################################
- 01_run1k | 8.92 | 19.17 | 32.01 | +66.99%
- 02_replace1k | 14.49 | 30.41 | 45.12 | +48.36%
+ 03_update10th1k_x16 | 1.60 | 3.18 | 2.99 | -6.08%
- 04_select1k | 0.44 | 5.12 | 5.68 | +10.77%
- 05_swap1k | 0.61 | 1.78 | 2.06 | +15.73%
- 06_remove-one-1k | 0.27 | 1.13 | 1.28 | +13.61%
- 07_create10k | 102.57 | 213.02 | 345.21 | +62.05%
- 08_create1k-after1k_x2 | 8.62 | 19.49 | 35.14 | +80.27%
- 09_clear1k_x8 | 23.69 | 27.51 | 39.28 | +42.80%
- 21_ready-memory | 1.66 | 1.65 | 1.70 | +3.17%
22_run-memory | 2.82 | 4.92 | 5.05 | +2.69%
- 23_update5-memory | 2.86 | 4.93 | 5.15 | +4.50%
- 25_run-clear-memory | 1.76 | 3.53 | 3.85 | +9.06%
+ 26_run-10k-memory | 13.38 | 41.70 | 33.19 | -20.41%
+ 41_size-uncompressed | 47.00 | 276.70 | 267.90 | -3.18%
+ 42_size-compressed | 14.50 | 66.60 | 64.50 | -3.15%
+ 43_first-paint | 119.80 | 506.60 | 488.10 | -3.65% Workflow: 8547975018 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-hydration
Area: client-side hydration
A-SSR
Area: Server Side Rendering (SSR) and Static Site Generation (SSG)
BREAKING CHANGE
Breaking changes introduced in this PR
C-enhancement
Category: new feature or improvement to existing feature
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closed in favor of #679
Finally, after having gone through a v3 version of our reactivity system with #612, it is time we rework the view system.
This PR eliminates
GenericNode
that was introduced all the way back in #67 to support both SSR and CSR. Both SSR and CSR are still supported via a different mechanism.Unlike Leptos, Dioxus, and many other up-and-coming Rust web frameworks, I choose not to use feature flags to differentiate between SSR and CSR mode. This is primarily because doing so would make features non-additive, meaning we cannot enable both at the same time.
In this PR, I have implemented SSR support by introducing a new
HtmlNode
type that acts a little like a virtual DOM node. Don't let that fool you, however, Sycamore still uses fine-grained reactivity for all DOM updates. Instead, what happens is that our view components constructs a static tree out of theseHtmlNode
s that describes the initial state of the UI. We then pass this tree to eitherDomRenderer
which will upgrade our tree into actual DOM nodes which can then be modified using reactivity, orSsrRenderer
which will directly serialize the tree to an HTML string.Closes #542
New builder API
Despite having re-worked the builder API in #373 for v0.7 and further small changes for v0.8, the builder API was still not very ergonomic to use. The builder API was always more of a second-class citizen relative to the
view!
macro.Before this PR, the builder API was an after-though. Now it is crucial. All HTML attributes are now fully type-checked (incidentally solving #556) via the builder API. The
view!
macro has also been dramatically simplified to just generating builder methods.For a taste, here is a comparaison between the old and the new builder API.
Closes #466, #556
Possibly resolved: #604
Hydration
We have
DomRenderer
for rendering to DOM nodes, we haveSsrRenderer
for rendering to a static string. And we also haveDomHydrateRenderer
for hydrating existing DOM nodes. This works differently from the existing implementation by first querying all the nodes withdata-hk
and storing them inside a list. This gives us a massive performance boost compared to querying every node seperately.Supersedes #537
Fixes #512 (needs confirmation)
Migration
The main change required is to remove all the pesky
<G: Html>
s and replaceView<G>
with simplyView
. This can easily be accomplished via a simple find-and-replace.Users of the builder API will need to migrate over to the new syntax. Unfortunately, there isn't much of a mechanical way of doing this other than following the new API,
Some smaller things involve changing
iterable
tolist
forKeyed
andIndexed
components.Finally, since attributes are now type-checked, invalid uses of attributes will now give a hard error. Another consequence is that since all attributes must be valid Rust identifiers, attributes such as
type
are nowr#type
. The specialref
attribute is still the same since it is specially handled by the macro.Remaining tasks:
HtmlNode
to make the coreView<T>
type usable for other renderers (e.g. native, tui, etc...)The core work of implementing this new rendering model has already been done so these tasks may be left for other PRs to speed up iteration time.
Also possibly fixed by this PR: #595