-
Notifications
You must be signed in to change notification settings - Fork 49.9k
[RN] Set up test to create public instances lazily in Fabric #32363
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,7 +57,10 @@ import { | |
| getInspectorDataForInstance, | ||
| } from './ReactNativeFiberInspector'; | ||
|
|
||
| import {passChildrenWhenCloningPersistedNodes} from 'shared/ReactFeatureFlags'; | ||
| import { | ||
| passChildrenWhenCloningPersistedNodes, | ||
| enableLazyPublicInstanceInFabric, | ||
| } from 'shared/ReactFeatureFlags'; | ||
| import {REACT_CONTEXT_TYPE} from 'shared/ReactSymbols'; | ||
| import type {ReactContext} from 'shared/ReactTypes'; | ||
|
|
||
|
|
@@ -93,8 +96,11 @@ export type Instance = { | |
| currentProps: Props, | ||
| // Reference to the React handle (the fiber) | ||
| internalInstanceHandle: InternalInstanceHandle, | ||
| // Exposed through refs. | ||
| publicInstance: PublicInstance, | ||
| // Exposed through refs. Potentially lazily created. | ||
| publicInstance: PublicInstance | null, | ||
| // This is only necessary to lazily create `publicInstance`. | ||
| // Will be set to `null` after that is created. | ||
| publicRootInstance?: PublicRootInstance | null, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there anyway we could retrieve this lazily from This is an extra slot for every single host component, which we should avoid if we can.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately The benchmarks I used took this field into account already, and even with this it should be a net win.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldn't expect this to show on benchmarks, but rather as memory overhead (increased overall heap size).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I only meant runtime performance when I was referencing the benchmarks. What I mean is that this change will overall reduce memory usage, even with that new field, as we'll avoid a large amount of allocations for unused refs. |
||
| }, | ||
| }; | ||
| export type TextInstance = { | ||
|
|
@@ -186,23 +192,37 @@ export function createInstance( | |
| internalInstanceHandle, // internalInstanceHandle | ||
| ); | ||
|
|
||
| const component = createPublicInstance( | ||
| tag, | ||
| viewConfig, | ||
| internalInstanceHandle, | ||
| rootContainerInstance.publicInstance, | ||
| ); | ||
|
|
||
| return { | ||
| node: node, | ||
| canonical: { | ||
| nativeTag: tag, | ||
| if (enableLazyPublicInstanceInFabric) { | ||
| return { | ||
| node: node, | ||
| canonical: { | ||
| nativeTag: tag, | ||
| viewConfig, | ||
| currentProps: props, | ||
| internalInstanceHandle, | ||
| publicInstance: null, | ||
| publicRootInstance: rootContainerInstance.publicInstance, | ||
| }, | ||
| }; | ||
| } else { | ||
| const component = createPublicInstance( | ||
| tag, | ||
| viewConfig, | ||
| currentProps: props, | ||
| internalInstanceHandle, | ||
| publicInstance: component, | ||
| }, | ||
| }; | ||
| rootContainerInstance.publicInstance, | ||
| ); | ||
|
|
||
| return { | ||
| node: node, | ||
| canonical: { | ||
| nativeTag: tag, | ||
| viewConfig, | ||
| currentProps: props, | ||
| internalInstanceHandle, | ||
| publicInstance: component, | ||
| }, | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| export function createTextInstance( | ||
|
|
@@ -277,7 +297,18 @@ export function getChildHostContext( | |
| } | ||
|
|
||
| export function getPublicInstance(instance: Instance): null | PublicInstance { | ||
| if (instance.canonical != null && instance.canonical.publicInstance != null) { | ||
| if (instance.canonical != null) { | ||
| if (instance.canonical.publicInstance == null) { | ||
| instance.canonical.publicInstance = createPublicInstance( | ||
| instance.canonical.nativeTag, | ||
| instance.canonical.viewConfig, | ||
| instance.canonical.internalInstanceHandle, | ||
| instance.canonical.publicRootInstance ?? null, | ||
| ); | ||
| // This was only necessary to create the public instance. | ||
| instance.canonical.publicRootInstance = null; | ||
| } | ||
|
|
||
| return instance.canonical.publicInstance; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add docs that this will be nulled out once
publicInstanceis created?