glimmerjs / glimmer-vm

MIT License
1.13k stars 191 forks source link

Re-review DOM sync approach. #1540

Open lifeart opened 11 months ago

lifeart commented 11 months ago

It seems we could explore different way to sync DOM with our state. Instead of tags revalidation, we could explicitly mark "invalid" tags and resolve related opcodes to it.

Pseudocode:

TAG_ID = 12;

OpcodesForTag = {
  [TAG_ID] = [UpdateAttr, UpdateTextContent]
}

TagsToRevalidate = [];

Tag {
   id = TAG_ID;
   update() {
       this.value = 42;
       TagsToRevalidate.push(this);
   }
}

While (TRUE) {
   TagsToRevalidate.ForEach(Tag => {
      const value = tag.value;
      OpcodesForTag[this.id].forEach( opcode => {
          opcode(value);
      });
   });
}

Here is sample implementation concept: https://codepen.io/lifeart/pen/abMzEZm?editors=0110

Includes:

image

Tldr:

current glimmer-vm tag invalidation approach: dirtryTag -> scheduleRerender -> validate all existing tags in application -> iterate over all opcodes and if changed -> execute approach in issue: dirtyTag -> scheduleRerender -> getOpcodesForTag(tag) -> execute

NullVoxPopuli commented 1 month ago

Now that we have perf testing in ci, a pr that does this would be very interesting!