question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature: move internal node nesting model to doubly linked lists

See original GitHub issue

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 mean

  • We remove ElementNode.__children
  • We add ElementNode.__first, which is either NodeKey or null.
  • We add ElementNode.__last, which is either NodeKey or null.
  • We add ElementNode.__size, which is number. Avoiding the need to do O(n) lookups to find the amount of children in the element.
  • We add LexicalNode._prev, which is either NodeKey or null.
  • We add LexicalNode._next, which is either NodeKey or null.

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.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:4
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

5reactions
trueadmcommented, Apr 18, 2022

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.

1reaction
acywatsoncommented, Jul 16, 2022

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”

https://github.com/facebook/lexical/pull/2044/files#diff-eae9d8a8a05fee2910d2082d36f6f1683ba3632596e8d9cab326ef1fb0651065R660

Read more comments on GitHub >

github_iconTop Results From Across the Web

Introduction and Insertion in a Doubly Linked List
A Doubly Linked List (DLL) contains an extra pointer, typically called the previous pointer, together with the next pointer and data which are ......
Read more >
Linked Lists I
Lists are doubly-linked, circular, and have a header node. Iterators are provided with two nested classes, named iterator and const_iterator, which satisfy ...
Read more >
Trying to write a swap position function for a doubly linked list
Ideally I would like to have a generic function that can handle all edge cases (moving to the begin, end and swapping random...
Read more >
Doubly Linked List In Java – Implementation & Code Examples
As each node needs to make space for the previous pointer, extra memory is required. · We need to deal with lots of...
Read more >
Javanotes 9, Solution to Exercise 3, Chapter 10
To implement this, I use linked lists in which each node contains both a key and ... This private nested class is used...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found