{"action":"opened","issue":{"url":"https://api.github.com/repos/evancz/elm-html/issues/103","repository_url":"https://api.github.com/repos/evancz/elm-html","labels_url":"https://api.github.com/repos/evancz/elm-html/issues/103/labels{/name}","comments_url":"https://api.github.com/repos/evancz/elm-html/issues/103/comments","events_url":"https://api.github.com/repos/evancz/elm-html/issues/103/events","html_url":"https://github.com/evancz/elm-html/issues/103","id":135347977,"number":103,"title":"Elements with event-handlers re-renders on every model update","user":{"login":"debois","id":187042,"avatar_url":"https://avatars.githubusercontent.com/u/187042?v=3","gravatar_id":"","url":"https://api.github.com/users/debois","html_url":"https://github.com/debois","followers_url":"https://api.github.com/users/debois/followers","following_url":"https://api.github.com/users/debois/following{/other_user}","gists_url":"https://api.github.com/users/debois/gists{/gist_id}","starred_url":"https://api.github.com/users/debois/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/debois/subscriptions","organizations_url":"https://api.github.com/users/debois/orgs","repos_url":"https://api.github.com/users/debois/repos","events_url":"https://api.github.com/users/debois/events{/privacy}","received_events_url":"https://api.github.com/users/debois/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-02-22T08:16:08Z","updated_at":"2016-02-22T08:16:08Z","closed_at":null,"body":"It seems that whenever I update my model, virtualdom will re-apply the on* properties on _every_ element that has such. The program will behave correctly, but performance could suffer, possibly quite badly if one has large numbers of such properties and high frequency of model updates (say, if you do animations). \r\n\r\nTo reproduce:\r\n\r\n    import StartApp.Simple\r\n    import Html exposing (..)\r\n    import Html.Events exposing (..)\r\n    import Html.Lazy\r\n    \r\n    type Action\r\n      = Click\r\n    \r\n    type alias Model = {}\r\n    \r\n    model : Model\r\n    model =\r\n      {\r\n      }\r\n    \r\n    view : Signal.Address Action -> Model -> Html\r\n    view addr _ =\r\n      Html.Lazy.lazy2 div\r\n        []\r\n        [ button\r\n            [ Html.Events.onClick addr Click ]\r\n            [text \"1. Click me\"]\r\n        , button\r\n            [ Html.Events.onClick addr Click ]\r\n            [text \"2. Click me\"]\r\n        ]\r\n    \r\n    \r\n    update : Action -> Model -> Model\r\n    update action model =\r\n      let _ = Debug.log \"Update: \" action\r\n      in\r\n        model\r\n    \r\n    main : Signal Html\r\n    main =\r\n        StartApp.Simple.start\r\n          { model = {}\r\n          , view = view\r\n          , update = update\r\n          }\r\n    \r\nIn your browser's debugger, set a breakpoint at index.html:8401 (inside virtualdom's `applyPatch`). Notice that clicking any button makes virtualdom apply a diff resetting the `onclick` property to _both_ buttons. \r\n\r\nI believe this happens because the [`on` function in Native.VirtualDom](https://github.com/evancz/virtual-dom/blob/master/src/Native/VirtualDom.js#L1392) produces a new closure on every call. Memoising `on` likely wouldn't help, since I imagine the `createMessage` argument to `on` would be (referentially) different on every call to `on` anyway. "}}