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

avm1: Store childNodes on the node itself #13319

Merged
merged 2 commits into from
Oct 16, 2023

Conversation

adrian17
Copy link
Collaborator

@adrian17 adrian17 commented Sep 25, 2023

I didn't do benchmarks yet. I can also add a test later.
This should help #13130 .
In general, this should make repeated .childNodes a free op, at the cost of making mutations (.appendChild etc) more expensive (O(n_children)* but only if .childNodes was read at least once before).
This is not just an optimization, but also a correctness fix, as the array mutations can be observed in AS.

(*which implies that appending N elements is O(n^2). I confirmed that FP has the same quadratic time complexity, though without benchmarks I can't tell whether we'll turn out faster or slower)

Unfortunately it's ugly due to current design. Ideally we'd want to refresh the array each time a mutation of a XmlNode (xml/tree.rs) happens, but this refresh is an AVM1 operation that technically can throw an AVM1 error, which makes actually calling this from tree.rs much harder.
Any advice? 😅

@@ -222,6 +222,8 @@ impl<'gc> Xml<'gc> {
}
}

self.root().refresh_cached_child_nodes(activation).unwrap(); // :(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think the AVM1 operations done by refresh_cached_child_nodes can throw an error?

@adrian17 adrian17 force-pushed the avm1-cache-child-nodes branch 2 times, most recently from d0a7c8f to cadeede Compare September 27, 2023 21:42
@adrian17 adrian17 marked this pull request as ready for review September 27, 2023 21:42
@Dinnerbone Dinnerbone force-pushed the avm1-cache-child-nodes branch from cadeede to 50da6d6 Compare October 16, 2023 09:03
@Dinnerbone Dinnerbone enabled auto-merge (rebase) October 16, 2023 09:03
@Dinnerbone Dinnerbone merged commit b02038b into ruffle-rs:master Oct 16, 2023
13 checks passed
@adrian17 adrian17 deleted the avm1-cache-child-nodes branch January 18, 2024 21:00
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