-
Notifications
You must be signed in to change notification settings - Fork 82
Open
Description
Edited by @evancz
The runtime behavior of justCirc and symAndUse is very different in the following code.
- With
symAndUsethe browser is recalculating styles on every animation frame. - With
justCircit does not do this.
You can observe this by profiling the example with the Chrome timeline
import Html exposing (Html)
import Svg exposing (..)
import Svg.Attributes exposing (..)
import VirtualDom exposing (attributeNS)
import AnimationFrame
import Time exposing (Time)
-- PROBLEM
view : Model -> Html Msg
view model =
let
justCirc = [ circle [cx "50", cy "50", r "40", strokeWidth "8", stroke "red", fill "red"] [] ]
symAndUse =
[ symbol [id "sym01"] justCirc
, use [xlinkHref "#sym01", x "0", y "0", width "100", height "100"] []
]
in
svg [ viewBox "0 0 200 200", width "600px" ]
--justCirc
symAndUse
-- SETUP
main = Html.program { init = init, view = view, update = update, subscriptions = subscriptions }
type alias Model = Time
init : (Model, Cmd Msg)
init =
(0, Cmd.none)
type Msg = Tick Time
update : Msg -> Model -> (Model, Cmd Msg)
update msg model =
case msg of
Tick newTime -> (0, Cmd.none)
subscriptions : Model -> Sub Msg
subscriptions model =
AnimationFrame.times TickOriginal Comment:
If you profile this example using the Chrome timeline, you can see that the browser is recalculating styles on every animation frame. Since the DOM isn't changing at all, this shouldn't be the case?
If you were to replace the last linesymAndUsewithjustCirc, it does work as expected (no calculating restyles).
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels