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

Simplify SimpleDOM casting (allow for proper production mode stripping) #1162

Merged
merged 1 commit into from Sep 24, 2020

Conversation

pzuraq
Copy link
Member

@pzuraq pzuraq commented Sep 18, 2020

The new cast function added for the recent TS upgrade has a couple of
issues:

  1. It creates wrapping objects which modify the values that are
    wrapped/casted. Removing cast(), as the production build currently
    does, breaks because of this.
  2. These wrapping objects conflate casting to SimpleDOM and casting
    away from it, into browser APIs.

The new system makes cast into two pure validation utility functions,
which either downlevels to SimpleDOM (without any checks, as SimpleDOM
is a subset of the real DOM), or uplevels to DOM with appropriate checks
(e.g. are we actually in the browser? Is the node a DOM node? Is it the
expected type of DOM node?).

The new `cast` function added for the recent TS upgrade has a couple of
issues:

1. It creates wrapping objects which modify the values that are
   wrapped/casted. Removing `cast()`, as the production build currently
   does, breaks because of this.
2. These wrapping objects conflate casting _to_ SimpleDOM and casting
   _away_ from it, into browser APIs.

The new system makes `cast` into two pure validation utility functions,
which either downlevels to SimpleDOM (without any checks, as SimpleDOM
is a subset of the real DOM), or uplevels to DOM with appropriate checks
(e.g. are we actually in the browser? Is the node a DOM node? Is it the
expected type of DOM node?).
@rwjblue
Copy link
Member

rwjblue commented Sep 22, 2020

The new cast function added for the recent TS upgrade has a couple of issues

Where/when were these issues identified?

It creates wrapping objects which modify the values that are wrapped/casted. Removing cast(), as the production build currently does, breaks because of this.

Does this indicate a lack of testing? Specifically, it would seem that we probably can't be testing the production builds (since this issue would have likely caused those tests to fail), right?

function isBrowserNode(node: Node | SimpleNode): node is Node {
return typeof document !== undefined && node.ownerDocument === document;
}
export function checkNode<S extends SugaryNodeCheck>(
Copy link
Member

Choose a reason for hiding this comment

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

Just to be clear, this is a DEBUG only utility (or actually, it may be a LOCAL_DEBUG?) right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it is LOCAL_DEBUG

@rwjblue rwjblue changed the title [BUGFIX] Simplify SimpleDOM casting Simplify SimpleDOM casting (allow for proper production mode stripping) Sep 22, 2020
@rwjblue
Copy link
Member

rwjblue commented Sep 22, 2020

Hmm. I don't fully grok why this would impact the performance check (~2% / 21ms slower). 🤔

A statistical analysis test was used (Wilcoxon Rank-Sum Test) to determine that the results are significant meaning they are worth looking at. A statistics estimator (Hodges–Lehmann estimator) was used to determine "Experiment" is slower by 21 ms. TracerBench is 95% confident it is slower between 3 ms to 38 ms based on 50 samples using a confidence interval.

@@ -30,13 +30,13 @@ class OnModifierManager implements ModifierManager<OnModifierState, null> {
install(state: OnModifierState) {
const name = valueForRef(state.nameRef);
const listener = valueForRef(state.listenerRef);
cast(state.element, 'ELEMENT').addEventListener(name, listener);
castToBrowser(state.element, 'ELEMENT').addEventListener(name, listener);
Copy link
Member

Choose a reason for hiding this comment

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

Is this removed for @glimmer/benchmark-env performance test also?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, it may not be, we can check

@pzuraq
Copy link
Member Author

pzuraq commented Sep 22, 2020

Production builds are not tested, no. It’s a gap we should probably prioritize filling

@rwjblue
Copy link
Member

rwjblue commented Sep 22, 2020

Production builds are not tested, no. It’s a gap we should probably prioritize filling

👍 totally agree, created #1165 to track that

@pzuraq
Copy link
Member Author

pzuraq commented Sep 24, 2020

It looks like there was some code that was not running at all in production builds due to the casting failure, specfically:

https://github.com/glimmerjs/glimmer-vm/blob/master/packages/%40glimmer/runtime/lib/compat/svg-inner-html-fix.ts#L31

https://github.com/glimmerjs/glimmer-vm/blob/master/packages/@glimmer/runtime/lib/compat/text-node-merging-fix.ts#L28

Tested by disabling these on this branch, and it seemed to move the needle back to mostly no stat-sig change, so I think that may have been the cause for the perf difference. This was clearly a bug, so I think it makes sense to merge and if we need to fixup perf in the future, find somewhere else to fix things.

@pzuraq pzuraq merged commit 5774aa1 into master Sep 24, 2020
@pzuraq pzuraq deleted the bugfix/simply-simple-cast branch September 24, 2020 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants