karaxnim / karax

Karax. Single page applications for Nim.
MIT License
1.07k stars 90 forks source link

Extremely slow diffing with nested nodes #111

Closed dawkot closed 5 years ago

dawkot commented 5 years ago

I tried this code compiled in release mode, nim version 0.20.2

import strutils
include karax / prelude

type Foo = ref object
  str: string

template foo(x): untyped = Foo(str: x)

var sequences: seq[seq[Foo]]

for i in 1..10:
  sequences.add @[foo"foo", foo"bar", foo"baz", foo"xyz", foo"abc"]

setRenderer proc: VNode =

  proc render(foo: Foo): VNode = buildHtml:
    button(id=foo.str):
      text foo.str
      proc onClick =
        if foo.str[0].isUpperAscii:
          foo.str[0] = foo.str[0].toLowerAscii
        else:
          foo.str[0] = foo.str[0].toUpperAscii

  buildHtml tdiv:
    tdiv:
      tdiv:
        tdiv:
          tdiv:
            tdiv:
              tdiv:
                tdiv:
                  for s in sequences:
                    for foo in s: render foo
                    br()

Chrome performance results: image

I don't think I can just use less divs to achieve the layout I want with the CSS framework I'm using.

Araq commented 5 years ago

Fixed.