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

custom snabbdom props module #108

Merged
merged 1 commit into from Dec 5, 2017

Conversation

cornerman
Copy link
Member

As discussed in #105, this adds a custom snabbdom props module, which compares against the actual element property.

Please do not merge, as I think, the generated code for scala-js is not as performant as a pure javascript implementation. So, we should implement this module in js and somehow include it with scalajs-bundler/webpack.

What do you think?

@cornerman
Copy link
Member Author

@fdietze fdietze force-pushed the snabbdom-props-mod branch 2 times, most recently from 26aae08 to c369c47 Compare December 3, 2017 18:43
@mariusmuja
Copy link
Collaborator

After reading snabbdom/snabbdom#345, I'd like to do some benchmarking on how this affects the performance for patching larger VNodes that contain multiple props.

@fdietze
Copy link
Member

fdietze commented Dec 3, 2017

@cornerman which properties are used by outwatch?

@cornerman
Copy link
Member Author

only these five props: value, checled, selected, textContent, indeterminate.

If we wanted we could also use the prop module for the reflected attributes, but there we currently use attributes.

@fdietze
Copy link
Member

fdietze commented Dec 3, 2017

The current alternatives to the custom snabbdom-module are:

Before taking the time to benchmark this approach, are there any other (theoretically) faster alternatives?

@cornerman
Copy link
Member Author

cornerman commented Dec 3, 2017

exactly, the ValueSyncHook did actually the same before for the value property. Here even reading the attribute AND the property:

  private val valueSyncHook: (VNodeProxy, VNodeProxy) => Unit = (_, node) => {
    node.elm.foreach { elm =>
      val input = elm.asInstanceOf[HTMLInputElement]
      if (input.value != input.getAttribute("value")) {
        input.value = input.getAttribute("value")
      }
    }
  }

@mariusmuja
Copy link
Collaborator

Agreed, all alternatives for keeping the DOM in sync seem to have similar trade-offs. Except that with the current snabbdom props, the DOM value only gets updated if it changed and the --> gets updates via Events, not from reading the DOM.

So, I don't know what the performance of the <--> alternative is, as for values it doesn't update the DOM on every keystroke, it reads the DOM on every keystroke event and skips updating because it didn't change)... something to benchmark.

Just occurred to me about reflected attributes... what is the performance of updating an attribute vs updating a prop (with the current snabbdom props module). Would the performance be better to use props instead for reflected attributes ( since most reflected attributes don't get changed by another agent)

@fdietze
Copy link
Member

fdietze commented Dec 3, 2017

So, I don't know what the performance of the <--> alternative is, as for values it doesn't update the DOM on every keystroke, it reads the DOM on every keystroke event and skips updating because it didn't change)... something to benchmark.

I don't understand what you are trying to say here. Most keystrokes on an input field change the value. So it only skips in the rare cases of keys which don't change it (e.g. arrow keys). Am I overlooking something?

@mariusmuja
Copy link
Collaborator

I don't understand what you are trying to say here. Most keystrokes on an input field change the value. So it only skips in the rare cases of keys which don't change it (e.g. arrow keys). Am I overlooking something?

I was thinking of the current props implementation that handles value as a special case and only writes the DOM prop it if the value changed compared to the actual DOM value. So, for something like this:

input(tpe := "text", value <-- strHandler, onInputString --> strHandler),

there is no DOM prop write on each keystoke, only a DOM prop read.

... but that's exactly what the proposed props module does too. And since outwatch is only updating 5 props though the props module and the rest are reflected attributes, I'm not so worried any more about the performance impact (I was forgetting earlier that we're using reflected attributes for all other props and I was worried about the performance impact of reading the DOM when updating each of them).

@cornerman
Copy link
Member Author

Just occurred to me about reflected attributes... what is the performance of updating an attribute vs updating a prop (with the current snabbdom props module). Would the performance be better to use props instead for reflected attributes ( since most reflected attributes don't get changed by another agent)

This is still a valid question, but I do not know of any benchmarks and how syncing between props and attributes actually behaves.

Copy link
Member

@LukaJCB LukaJCB 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 working on this!

@fdietze fdietze force-pushed the snabbdom-props-mod branch 2 times, most recently from 542b3d0 to 5824d7a Compare December 5, 2017 16:45
The ground truth is now the dom instead of the vdom. This allows to
handle user input easily and correctly.
@fdietze fdietze merged commit 441298a into outwatch:master Dec 5, 2017
@fdietze fdietze deleted the snabbdom-props-mod branch December 5, 2017 17: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.

None yet

4 participants