Skip to content

Conversation

@webbeef
Copy link
Contributor

@webbeef webbeef commented Nov 21, 2025

When using the iterator nodes are rooted but they are dropped immediately.

Testing: Green wpt run: https://github.com/webbeef/servo/actions/runs/19560383039/job/56012660243

Signed-off-by: webbeef <me@webbeef.org>
@webbeef webbeef requested a review from gterzian as a code owner November 21, 2025 05:55
@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Nov 21, 2025
@simonwuelker
Copy link
Contributor

Nice! I wonder if it is possible to address this by making Node::ancestors return &Node, using a streaming iterator, without losing too much convenience...

@jdm
Copy link
Member

jdm commented Nov 21, 2025

Nice! I wonder if it is possible to address this by making Node::ancestors return &Node, using a streaming iterator, without losing too much convenience...

I don't think that is an API that we can generalize safely without still ensuring the node is rooted somewhere.

@mrobinson
Copy link
Member

From what I understand (please correct me if I'm wrong), MutNullableDom still needs to do Dom::from_ref() internally (which accesses TLS on non-production builds). I experimented briefly with making a lifetime-bound iterator that worked only with Dom<Node>, but wasn't able to get it working. Maybe there is a way though.

@mrobinson
Copy link
Member

Idly, I also wonder if we are simply optimizing non-production builds here as the TLS is accessed via debug_assert!.

@webbeef
Copy link
Contributor Author

webbeef commented Nov 21, 2025

Idly, I also wonder if we are simply optimizing non-production builds here as the TLS is accessed via debug_assert!.

I take profiles from a profiling build. If they are not representative of production ones we need to update their configuration.

Here we also avoid the whole rooting/unrooting which is not free anyway. I agree that we lose in ergonomics and that's annoying. There are many other places in node.rs that could benefit from a similar treatment (many if some_iterator().any(...) occurences) but that would become quite unreadable.

@simonwuelker
Copy link
Contributor

Nice! I wonder if it is possible to address this by making Node::ancestors return &Node, using a streaming iterator, without losing too much convenience...

I don't think that is an API that we can generalize safely without still ensuring the node is rooted somewhere.

It is if the reference refers to the iterator, which holds the root. But that requires fn next<'a>(&'a mut self) -> Option<&'a Node>, which is not compatible with the Iterator trait.

@jschwe
Copy link
Member

jschwe commented Nov 23, 2025

Idly, I also wonder if we are simply optimizing non-production builds here as the TLS is accessed via debug_assert!.

I take profiles from a profiling build. If they are not representative of production ones we need to update their configuration.

debug_assertions are disabled in profiling builds. The only difference is presence of debug information (should not affect perf) and that lto is thin instead of fat, which should only have a minor impact (and reduced link-time significantly).

Copy link
Member

@jdm jdm left a comment

Choose a reason for hiding this comment

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

I'd like to find more usable abstractions for code like this in the future, but I don't have good ideas to propose right now.

@servo-highfive servo-highfive removed the S-awaiting-review There is new code that needs to be reviewed. label Nov 28, 2025
@jdm jdm added this pull request to the merge queue Nov 28, 2025
@servo-highfive servo-highfive added the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Nov 28, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 28, 2025
@servo-highfive servo-highfive added S-tests-failed The changes caused existing tests to fail. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Nov 28, 2025
@jdm jdm added this pull request to the merge queue Nov 28, 2025
@servo-highfive servo-highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-tests-failed The changes caused existing tests to fail. labels Nov 28, 2025
Merged via the queue into servo:main with commit d735419 Nov 28, 2025
41 checks passed
@servo-highfive servo-highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Nov 28, 2025
delan added a commit that referenced this pull request Nov 29, 2025
…ows linux lint)

{"fail_fast": false, "matrix": [{"name": "Windows", "workflow": "windows", "wpt": false, "profile": "release", "unit_tests": false, "build_libservo": false, "bencher": false, "coverage": false, "build_args": "", "wpt_args": "", "number_of_wpt_chunks": 20}, {"name": "Linux", "workflow": "linux", "wpt": false, "profile": "release", "unit_tests": false, "build_libservo": false, "bencher": false, "coverage": false, "build_args": "", "wpt_args": "", "number_of_wpt_chunks": 20}, {"name": "Lint", "workflow": "lint", "wpt": false, "profile": "release", "unit_tests": false, "build_libservo": false, "bencher": false, "coverage": false, "build_args": "", "wpt_args": "", "number_of_wpt_chunks": 20}]}
delan added a commit that referenced this pull request Nov 29, 2025
…ows linux lint)

{"fail_fast": false, "matrix": [{"name": "Windows", "workflow": "windows", "wpt": false, "profile": "release", "unit_tests": false, "build_libservo": false, "bencher": false, "coverage": false, "build_args": "", "wpt_args": "", "number_of_wpt_chunks": 20}, {"name": "Linux", "workflow": "linux", "wpt": false, "profile": "release", "unit_tests": false, "build_libservo": false, "bencher": false, "coverage": false, "build_args": "", "wpt_args": "", "number_of_wpt_chunks": 20}, {"name": "Lint", "workflow": "lint", "wpt": false, "profile": "release", "unit_tests": false, "build_libservo": false, "bencher": false, "coverage": false, "build_args": "", "wpt_args": "", "number_of_wpt_chunks": 20}]}
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.

6 participants