-
Notifications
You must be signed in to change notification settings - Fork 27
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
Thoughts on an html! macro that emits an impl Read value #37
Comments
Glad it's useful!
Not sure if that's actually the case? It does end up with a potentially really large
That sounds like an useful and more elegant way to solve it – and I can't think of any larger gotchas! If you come up with something, I'd be also interested in changing the |
Live.View looks pretty interesting and broadly similar to what htmx does. From a glance the major difference may be the simplicity of the server side: htmx doesn't have any system for managing client state, it simply serves html pages or fragments (serving fragments is the 'novel' part) in response to plain http requests. You're right, walk_nodes only appends strings and expressions in a single call to Here's a (contrived) example of what I mean. This is way more atomized than I would expect a normal app to be, but it still demonstrates the issue I'm pointing at:
Just to follow along explicitly, htmx encourages some fragmentation (not to this degree of course) because you're meant to be able to make a request, say for row 33, and the server will respond with just that row as an html fragment. |
On a scale of "make it work, make it right, make it fast", this issue is on the "make it fast" side, and may reasonably be prioritized below #48 which is closer to the "make it right" side imo. Note, the linked commit, 9626096, includes a technique to serialize string literals directly into the format string (as opposed to providing them as separate args) which could improve rendering performance. |
Hi! First I want to say thank you for making this library! I appreciate the features and principles you aimed for, especially "non opinionated" parser that accepts any xml-like pattern, the minimal dependencies (especially avoiding wasm-bindgen), and a modular design that exposes the parsed node tree as a base to build any kind of macro on top of.
Because of these features I was able to easily integrate
html-to-string-macro
into a demo project based around htmx, a library that adds interactivity to html by requesting html fragments over http and inserting them into the DOM (an approach that offers more bang-for-buck than its simplistic appearance indicates). (See also htmx intro presentation if you like.)I'd like to expand this demo project to be something more, but I'm concerned that that deeply recursive use of
html-to-string-macro
'shtml!
would lead to O(n²) performance due to repeatedly callingformat!
on larger and larger fragments of the page as the page is gradually built up.To solve this I'm thinking about writing a new implementation of the
html!
macro, maybe calledhtml-to-reader-macro
, that instead of emitting a String it emits a value that implements the Read trait. The idea being that you can build up a big graph of objects that impl Read and then calling read() on the root will traverse through the component tree and scan out all the bytes directly into the final destination buffer exactly once with no unnecessary intermediate copying.What do you think? Useful? Feasible? Gotchas?
The text was updated successfully, but these errors were encountered: