Skip to content

Feature: forgetti/runtime #2

@lxsmnsyc

Description

@lxsmnsyc

This is a thread discussing the introduction of forgetti/runtime, which would provide APIs that aren't achievable alone by the compiler.

$$equals(a, b)

Object.is is the slowest of the three comparison methods, the other being == and ===. equal provides a short path to allow using referential equality on non-number types.

Ideal implementation would look like:

function equals<T, R>(a: T, b: T) {
  return a === b || (a !== a && b !== b);
}

$$cache(useMemo, size)

  • This simplifies the output for the root cache.
  • Also adds other fields that may be useful (to be discussed in the latter part of the list).

$$effect(effectHook, index, callback, dependency)

  • This allows effect hooks to be unlocked from the hook rules.
  • Relies on the new $$cache

$$childCache(size)

  • Allows for 3P hooks to unlock its own hook rules by accessing the underlying root or parent cache. Previously it created its own root cache.

$$memo(memoHoc, Component, keys)

  • Memoizes components with monomorphic props.

Template splitting

This is still a pending design. The aim is for to split the template part from the logical part, producing a stateless memoized component. The design has the following considerations:

Splitting strategies

Per-element split

This solution aims to split every JSX element to be a standalone memoized component. This is definitely granular, but may consume too much memory

Singular template split

This solution only splits for the top-level JSX element. It has the same memoization process as the first solution except that the entirety is now grouped and is probably cheaper.

Component reference checking

This solution only applies memoization for potentially unmemoized components. The split creates a wrapper component at top-level and uses $$memo. Under the hood, $$memo decides if it should memoized the component by checking some key properties (either checking the component's name via React or assigning a symbol).

New JSX runtime

Maybe worth looking at?

Inspiration:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions