Skip to content

Optimize CompositeBackgroundDrawable#47618

Closed
jorge-cab wants to merge 2 commits into
facebook:mainfrom
jorge-cab:export-D65907786
Closed

Optimize CompositeBackgroundDrawable#47618
jorge-cab wants to merge 2 commits into
facebook:mainfrom
jorge-cab:export-D65907786

Conversation

@jorge-cab
Copy link
Copy Markdown
Contributor

Summary:
Its not optimal to reconstruct CompositeBackgroundDrawable everytime we add a layer to it.

With this change I'm adding an optimization to modify the underlying LayerDrawable in place instead of reconstructing everything. LayerDrawable has a pretty constrained API and some weirdish behaviors.

  • addLayer - This API doesnt set the callback for the recently added layer so after adding the layer we also need to manually set the callback
  • Mutating LayerDrawable in-place is not straightforward, I had to add a function that will figure out where each layer should be inserted
  • LayerDrawable doesn't allow deleting an element which means that for this case in particular we do need to re-create CompositeBackgroundDrawable
  • Newer Android versions allow null on LayerDrawable layers, but older versions do not, this implementation is mostly done this way to accommodate older versions. But also, even though newer versions can have null set on a layer LayerDrawable still doesn't handle it well and we get some bugs when removing and inserting a layer

This is all feature flagged. since it will only be enabled with the new drawables

Changelog: [Internal]

Differential Revision: D65907786

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Facebook Partner: Facebook Partner labels Nov 14, 2024
@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D65907786

@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D65907786

@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D65907786

@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D65907786

@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D65907786

Summary:

Before we were using lists which meant `CompositeBackgroundDrawable` had a `LayerDrawable` of variable length. 

This meant that our layers were not consistent and made it hard to optimize `CompositeBackgroundDrawable` to not create a new instance every time we set a new Layer.  

With this change `CompositeBackgroundDrawable` has a consistent amount of layers which will allow us to more easily mutate it and land the optimization present on D63287222

Changelog: [Internal]

Reviewed By: NickGerleman

Differential Revision: D63798842
Summary:

Its not optimal to reconstruct CompositeBackgroundDrawable everytime we add a layer to it. 

With this change I'm adding an optimization to modify the underlying `LayerDrawable` in place instead of reconstructing everything. `LayerDrawable` has a pretty constrained API and some weirdish behaviors. 

- `addLayer` - This API doesnt set the callback for the recently added layer so after adding the layer we also need to manually set the callback
- Mutating `LayerDrawable` in-place is not straightforward, I had to add a function that will figure out where each layer should be inserted
- `LayerDrawable` doesn't allow deleting an element which means that for this case in particular we do need to re-create `CompositeBackgroundDrawable`
- Newer Android versions allow `null` on `LayerDrawable` layers, but older versions do not, this implementation is mostly done this way to accommodate older versions. But also, even though newer versions can have `null` set on a layer `LayerDrawable` still doesn't handle it well and we get some bugs when removing and inserting a layer which the current implementation handles by not relying on null

This is all feature flagged. since it will only be enabled with the new drawables

Changelog: [Internal]

Reviewed By: joevilches

Differential Revision: D65907786
@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D65907786

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Nov 19, 2024
@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request has been merged in 61f01ad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged This PR has been merged. p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants