-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Feature: move internal node nesting model to doubly linked lists #1860
Comments
Should mark it as a breaking change since state format will be changed |
I think we probably want to introduce this to start with, in addition to the existing API. Have them both there, then switch, then remove the old in v0.3. So we'll be duplicating work for a short-time, to ensure backwards compatibility. |
Work in progress in #2044 As a general FYI, we reprioritized this behind the JSON serialization changes, since those were important to insulate users against breaking changes to our internal node schemas (like re-implementing the state to use linked lists 😄 ) |
I was planning to suggest/work on this later, but I see you have already noticed this opportunity for improvement as well. Just an observation. My intuition tells me that single linked list will be even more performant than double linked list. Most operations, like rendering, need only the next sibling. In case there are a few occasional operations that need the previous sibling, I don't think such savings in operations outweigh duplicating every other operation that a simple linked list model would require. |
InsertBefore and delete would be linear vs constant with dll. And delete is one of (if not the most) used op since whenever node is moved around it's deleted from current parent first |
delete is a method of LexicalNode or ElementNode? Could you tell me where in the code it is? I'm not seeing it |
It’s actually called “remove” |
@trueadm did this! |
Today, Lexical nodes are nested using arrays. This means that
ElementNode
references an array of child node keys. However, we can improve performance by switching away from arrays, and to using doubly linked lists. This would meanElementNode.__children
ElementNode.__first
, which is eitherNodeKey
ornull
.ElementNode.__last
, which is eitherNodeKey
ornull
.ElementNode.__size
, which isnumber
. Avoiding the need to do O(n) lookups to find the amount of children in the element.LexicalNode._prev
, which is eitherNodeKey
ornull
.LexicalNode._next
, which is eitherNodeKey
ornull
.When we add/remove a node, we'll need to make sure to update the linked list of both adjacent siblings (
__prev
and__next
). Additionally, if the node is the first or last node of its parent, we'll also have to update the parent__size
,__first
and/or__last
. We can remove the logic we have for marking siblings dirty, as we'll do that organically from using linked lists.The text was updated successfully, but these errors were encountered: