Optimize CompositeBackgroundDrawable#47618
Closed
jorge-cab wants to merge 2 commits into
Closed
Conversation
Contributor
|
This pull request was exported from Phabricator. Differential Revision: D65907786 |
3bae7a3 to
a8ae9bd
Compare
Contributor
|
This pull request was exported from Phabricator. Differential Revision: D65907786 |
a8ae9bd to
d867a59
Compare
Contributor
|
This pull request was exported from Phabricator. Differential Revision: D65907786 |
d867a59 to
8719e8d
Compare
Contributor
|
This pull request was exported from Phabricator. Differential Revision: D65907786 |
8719e8d to
baa06e4
Compare
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
baa06e4 to
050cb53
Compare
Contributor
|
This pull request was exported from Phabricator. Differential Revision: D65907786 |
Contributor
|
This pull request has been merged in 61f01ad. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
LayerDrawablein place instead of reconstructing everything.LayerDrawablehas 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 callbackLayerDrawablein-place is not straightforward, I had to add a function that will figure out where each layer should be insertedLayerDrawabledoesn't allow deleting an element which means that for this case in particular we do need to re-createCompositeBackgroundDrawablenullonLayerDrawablelayers, but older versions do not, this implementation is mostly done this way to accommodate older versions. But also, even though newer versions can havenullset on a layerLayerDrawablestill doesn't handle it well and we get some bugs when removing and inserting a layerThis is all feature flagged. since it will only be enabled with the new drawables
Changelog: [Internal]
Differential Revision: D65907786