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

add modifiers to debug render tree #1559

Merged

Conversation

patricklx
Copy link
Contributor

No description provided.

@patricklx patricklx force-pushed the add-modifiers-to-debug-render-tree branch from 8769217 to a9d1be4 Compare February 5, 2024 11:28
QUnit.on('testEnd', (testEnd) => {
if (testEnd.status === 'failed') {
testEnd.errors.forEach((assertion) => {
console.error(assertion.stack);
Copy link
Contributor Author

@patricklx patricklx Feb 5, 2024

Choose a reason for hiding this comment

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

prints error stack traces from tests to console, useful for debugging, like clicking on error location to jump to the code

@patricklx patricklx force-pushed the add-modifiers-to-debug-render-tree branch 4 times, most recently from d9cf236 to d8abb13 Compare February 5, 2024 14:54
@chancancode
Copy link
Contributor

I am not sure that it is a good idea to add more work here, especially to the close element operation which affects every single element we render which can add up. I don’t love the architecture of the inspector integration today, the code is not strippable, has some non-zero impact even when it’s not enabled, and IIRC it’s enabled pretty much any time that the inspector is installed, not just when the inspector is visible or the rendering tab is selected. We probably need to think harder about whether that is ok before adding even more work there, especially something as impactful as this.

Doing it for modifiers itself is probably not an issue, it’s the fact that you need some way to tie it to the element and that led you to add HTML nodes to the tree that is the problem. Beyond what I said above it will also make the tree vastly bigger and you may run into slowness in serializing the tree and sending it over to the inspector. That happens every time something changes and causes a re-render (even for no-op re-render).

If you just want to add modifier node without introducing html element parents here I think that would be fine. We still give you a reference to the element anyway and you can probably still group them in the inspector’s processing code if you want.

@patricklx
Copy link
Contributor Author

@chancancode i tried to improve the performance by checking with a Set.
It actually only creates the html element if there are modifiers.
I also wanted components that are under the html element to actually appear under the element.
If this is still not okay, i could also just create the html element in the pushModifiers call and close it immediately afterwards. That shouldn't cause much more perf issues

@@ -84,7 +84,7 @@ export class NewElementBuilder implements ElementBuilder {
[CURSOR_STACK] = new Stack<Cursor>();
private modifierStack = new Stack<Nullable<ModifierInstance[]>>();
private blockStack = new Stack<LiveBlock>();
private htmlElementsState: { shouldAddHtmlElement?: boolean }[];
private htmlElementsState = new Set();
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe you are not fully done, but to be clear about what I meant in the comment – in the final state of the PR (w.r.t. "I think it would be fine if we just want to add modifiers to the tree without adding elements"), this should not even be needed, and that we wouldn't have added the new "html-element" type to the tree at all. When I say you can infer and group them in the inspector if you want to, I mean you can do that using the bounds, which would presumably reference the element they are attached to, and then you can recreate the grouping with a weak map or something on the inspector side.

And, yes, if it's feasible and about the same amount of code, it would probably be a good idea to do the work in pushModifier rather than in closeElement, all else being equal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so, now there is a html element which wraps only the modifiers. the rest can be done in inspector

Copy link
Contributor

Choose a reason for hiding this comment

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

As I was saying above, let’s not even add that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

Copy link
Contributor

@chancancode chancancode left a comment

Choose a reason for hiding this comment

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

see above

@patricklx patricklx force-pushed the add-modifiers-to-debug-render-tree branch from ce6ec47 to 8b98f28 Compare February 7, 2024 09:00
@patricklx
Copy link
Contributor Author

patricklx commented Feb 12, 2024

@chancancode i update the PR.
by the way, inspector does not serialize+send every time something changes. I did improve the inspector long time ago to limit the calls to debug render tree (and serialize+send) to once per 250ms.
Maybe if someone has many items of components+modifiers it starts slowing down . But I also have an idea for that, at least at inspector side.

@chancancode
Copy link
Contributor

chancancode commented Feb 27, 2024

Gonna circle back to the inspector stuff after finishing #1568 (which could use a review from you)

@patricklx
Copy link
Contributor Author

patricklx commented Feb 27, 2024

I found that in-element needed to add a destructor to release it in the debug render tree. Does this also need something similar?

@patricklx
Copy link
Contributor Author

I think i move everything to

export class CustomModifierManager<O extends Owner, ModifierInstance>

@patricklx patricklx force-pushed the add-modifiers-to-debug-render-tree branch 3 times, most recently from 446661a to d066dba Compare February 27, 2024 14:26
@chancancode chancancode force-pushed the add-modifiers-to-debug-render-tree branch from d066dba to 9150788 Compare March 8, 2024 20:37
registerDestructor(state, () => {
vm.env.debugRenderTree?.willDestroy(state);
});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Most of these are analogous to the component equivalent in the same file

@chancancode chancancode force-pushed the add-modifiers-to-debug-render-tree branch 2 times, most recently from 8b2c275 to facb979 Compare March 8, 2024 21:40
@chancancode chancancode force-pushed the add-modifiers-to-debug-render-tree branch from facb979 to bfeebae Compare March 9, 2024 01:29
@chancancode chancancode force-pushed the add-modifiers-to-debug-render-tree branch from bfeebae to 1b47565 Compare March 9, 2024 02:03
Copy link
Contributor

@NullVoxPopuli NullVoxPopuli left a comment

Choose a reason for hiding this comment

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

Thanks for doing putting this together! and the test was most helpful in helping understand what's expected of the debug render tree for modifiers <3

@NullVoxPopuli NullVoxPopuli merged commit 9bfc4dd into glimmerjs:main Mar 9, 2024
6 checks passed
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.

3 participants