Skip to content
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

Optimize maybeHideFeedback for initial page render #2953

Merged

Conversation

Schultzer
Copy link
Contributor

This PR optimizes the initial page render for pages containing thousands of inputs; instead of calling DOM.all for each input, we build a selector to match all inputs and query the DOM.

From my testing, this has reduced the page rendering time from over 30 seconds to 4-5 seconds.

This PR optimizes the initial page render for pages containing thousands of inputs; instead of calling `DOM.all` for each input, we build a selector to match all inputs and query the DOM.

From my testing, this has reduced the page rendering time from over 30 seconds to 4-5 seconds.
if(!(this.private(input, PHX_HAS_FOCUSED) || this.private(input, PHX_HAS_SUBMITTED))){
let feedbacks = [input.name]
if(input.name.endsWith("[]")){ feedbacks.push(input.name.slice(0, -2)) }
selector = feedbacks.map(f => `[${phxFeedbackFor}="${f}"]`).join(", ")
Copy link
Member

Choose a reason for hiding this comment

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

this discards the previous selector. Instead you can accumulate the feedbacks, then join the into a selector on the outside of the forEach

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I've pushed a commit that leverages the feedback for accumulation. I still see improvements on pages containing thousands of inputs; I need a better understanding of LiveView's JS and Morphdom to determine if there is a better way to improve the initial page render for pages that stream thousands of inputs.

@chrismccord chrismccord merged commit 297a782 into phoenixframework:main Dec 18, 2023
@chrismccord
Copy link
Member

❤️❤️❤️🐥🔥

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

Successfully merging this pull request may close these issues.

None yet

2 participants