| 30 | |
| 31 | == The relationship between wrappers and DOM objects == |
| 32 | |
| 33 | === Option 1: Wrappers are mandatory |
| 34 | |
| 35 | This approach creates wrappers for all DOM objects. |
| 36 | |
| 37 | Pros: |
| 38 | * GC is simplified. Since all DOM tree edges are represented in the JS side, GC does not need to transfer information between a JS engine and WebKit. |
| 39 | |
| 40 | Cons: |
| 41 | * We need to create wrappers for DOM objects that are not touched by JS. This would not be a problem for JS-heavy workloads but might become a problem for JS-light workloads. For JS-light workloads, the mandatory-wrapper approach might end up increasing the number of wrappers in a JS heap and regresses performance of GC. |
| 42 | |
| 43 | === Option 2: Wrappers are optional |
| 44 | |
| 45 | This approach creates wrappers for only DOM objects that are touched by JS as is done in the current JSC/V8 + WebKit. As a fast path, in a case where a wrapper object exists, .nextSibling is realized by normal JavaScript property access. As a slow path, in a case where a wrapper object does not exist, .nextSibling is realized by Node::nextSibling() as is done in the current WebKit. |
| 46 | |
| 47 | Pros: |
| 48 | * For JS-light workloads, the optional-wrapper approach would be faster than the mandatory-wrapper approach. The optional-wrapper approach does not need to create wrappers just for representing tree edges. |
| 49 | |
| 50 | Cons: |
| 51 | * GC is not simplified. Since some tree edges are represented in the JS side and other tree edges are represented in the WebKit side, GC still needs to transfer information between a JS engine and WebKit. |
| 52 | * We need to reserve space for .firstChild, .nextSibling, etc on both WebKit and JavaScript. |