Attributes Metadata

Summary:
Before this change, attributes and attribute metadata were intermingled and sent as one unit via subtree update event.

This represented a few issues:
- Repetitiveness. For each declared and dynamic attribute, metadata was included on each value unit.
- Metadata can vary in size and thus can have a negative impact on payload size.
- The attribute name which is part of metadata is a string which always overhead on processing.
- Metadata instantiation is not cheap thus this also incurs in processing overhead i.e. even instantiating a single string can have an impact.

The proposal is to separate metadata of attributes from the actual node reported attributes. This solves the problems mentioned above.

Reviewed By: LukeDefeo

Differential Revision: D40674156

fbshipit-source-id: 0788551849fbce53065f819ba503e7e4afc03cc0
This commit is contained in:
Lorenzo Blasa
2022-11-10 11:52:28 -08:00
committed by Facebook GitHub Bot
parent 27428522ce
commit 01dc22b1ab
33 changed files with 663 additions and 267 deletions

View File

@@ -8,16 +8,15 @@
package com.facebook.flipper.plugins.uidebugger.litho.descriptors
import android.graphics.Bitmap
import com.facebook.flipper.plugins.uidebugger.descriptors.BaseTags
import com.facebook.flipper.plugins.uidebugger.descriptors.DescriptorRegister
import com.facebook.flipper.plugins.uidebugger.descriptors.NodeDescriptor
import com.facebook.flipper.plugins.uidebugger.descriptors.OffsetChild
import com.facebook.flipper.plugins.uidebugger.descriptors.*
import com.facebook.flipper.plugins.uidebugger.litho.LithoTag
import com.facebook.flipper.plugins.uidebugger.model.Bounds
import com.facebook.flipper.plugins.uidebugger.model.InspectableObject
import com.facebook.flipper.plugins.uidebugger.model.MetadataId
import com.facebook.litho.DebugComponent
class DebugComponentDescriptor(val register: DescriptorRegister) : NodeDescriptor<DebugComponent> {
private val NAMESPACE = "DebugComponent"
override fun getName(node: DebugComponent): String {
return node.component.simpleName
@@ -54,7 +53,15 @@ class DebugComponentDescriptor(val register: DescriptorRegister) : NodeDescripto
override fun getActiveChild(node: DebugComponent): Any? = null
override fun getData(node: DebugComponent) = mapOf<String, InspectableObject>()
private val LayoutId =
MetadataRegister.register(MetadataRegister.TYPE_LAYOUT, NAMESPACE, "Litho Layout")
private val UserPropsId =
MetadataRegister.register(MetadataRegister.TYPE_ATTRIBUTE, NAMESPACE, "User Props")
override fun getData(node: DebugComponent): Map<MetadataId, InspectableObject> {
val attributeSections = mutableMapOf<MetadataId, InspectableObject>()
return attributeSections
}
override fun getBounds(node: DebugComponent): Bounds =
Bounds.fromRect(node.boundsInParentDebugComponent)

View File

@@ -8,15 +8,19 @@
package com.facebook.flipper.plugins.uidebugger.litho.descriptors
import com.facebook.flipper.plugins.uidebugger.descriptors.ChainedDescriptor
import com.facebook.flipper.plugins.uidebugger.descriptors.SectionName
import com.facebook.flipper.plugins.uidebugger.model.Inspectable
import com.facebook.flipper.plugins.uidebugger.descriptors.MetadataRegister
import com.facebook.flipper.plugins.uidebugger.model.InspectableObject
import com.facebook.flipper.plugins.uidebugger.model.InspectableValue
import com.facebook.flipper.plugins.uidebugger.model.MetadataId
import com.facebook.litho.DebugComponent
import com.facebook.litho.LithoView
object LithoViewDescriptor : ChainedDescriptor<LithoView>() {
private const val NAMESPACE = "LithoView"
private val SectionId =
MetadataRegister.register(MetadataRegister.TYPE_ATTRIBUTE, NAMESPACE, NAMESPACE)
override fun onGetName(node: LithoView): String = node.javaClass.simpleName
override fun onGetChildren(node: LithoView): List<Any> {
@@ -28,14 +32,18 @@ object LithoViewDescriptor : ChainedDescriptor<LithoView>() {
return result
}
private val IsIncrementalMountEnabledAttributeId =
MetadataRegister.register(
MetadataRegister.TYPE_ATTRIBUTE, NAMESPACE, "isIncrementalMountEnabled")
override fun onGetData(
node: LithoView,
attributeSections: MutableMap<SectionName, InspectableObject>
attributeSections: MutableMap<MetadataId, InspectableObject>
) {
attributeSections["Litho"] =
attributeSections[SectionId] =
InspectableObject(
mapOf<String, Inspectable>(
"isIncrementalMountEnabled" to
InspectableValue.Boolean(node.isIncrementalMountEnabled, false)))
mapOf(
IsIncrementalMountEnabledAttributeId to
InspectableValue.Boolean(node.isIncrementalMountEnabled)))
}
}

View File

@@ -11,6 +11,7 @@ import android.graphics.Bitmap
import com.facebook.flipper.plugins.uidebugger.descriptors.*
import com.facebook.flipper.plugins.uidebugger.model.Bounds
import com.facebook.flipper.plugins.uidebugger.model.InspectableObject
import com.facebook.flipper.plugins.uidebugger.model.MetadataId
/** a drawable or view that is mounted, along with the correct descriptor */
class MountedObject(val obj: Any, val descriptor: NodeDescriptor<Any>)
@@ -37,7 +38,7 @@ object MountedObjectDescriptor : NodeDescriptor<MountedObject> {
override fun getActiveChild(node: MountedObject): Any? = node.descriptor.getActiveChild(node.obj)
override fun getData(node: MountedObject): Map<SectionName, InspectableObject> =
override fun getData(node: MountedObject): Map<MetadataId, InspectableObject> =
node.descriptor.getData(node.obj)
override fun getTags(node: MountedObject): Set<String> = node.descriptor.getTags(node.obj)

View File

@@ -8,23 +8,30 @@
package com.facebook.flipper.plugins.uidebugger.litho.descriptors
import com.facebook.flipper.plugins.uidebugger.descriptors.ChainedDescriptor
import com.facebook.flipper.plugins.uidebugger.descriptors.SectionName
import com.facebook.flipper.plugins.uidebugger.descriptors.MetadataRegister
import com.facebook.flipper.plugins.uidebugger.model.Inspectable
import com.facebook.flipper.plugins.uidebugger.model.InspectableObject
import com.facebook.flipper.plugins.uidebugger.model.InspectableValue
import com.facebook.flipper.plugins.uidebugger.model.MetadataId
import com.facebook.litho.widget.TextDrawable
object TextDrawableDescriptor : ChainedDescriptor<TextDrawable>() {
private const val NAMESPACE = "TextDrawable"
private val SectionId =
MetadataRegister.register(MetadataRegister.TYPE_ATTRIBUTE, NAMESPACE, NAMESPACE)
override fun onGetName(node: TextDrawable): String = node.javaClass.simpleName
private val TextAttributeId =
MetadataRegister.register(MetadataRegister.TYPE_ATTRIBUTE, NAMESPACE, "text")
override fun onGetData(
node: TextDrawable,
attributeSections: MutableMap<SectionName, InspectableObject>
attributeSections: MutableMap<MetadataId, InspectableObject>
) {
val props =
mapOf<String, Inspectable>("text" to InspectableValue.Text(node.text.toString(), false))
mapOf<Int, Inspectable>(TextAttributeId to InspectableValue.Text(node.text.toString()))
attributeSections["TextDrawable"] = InspectableObject(props)
attributeSections[SectionId] = InspectableObject(props)
}
}