Batch application of style properties #3273
Open
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.
This consists of a few related changes that cut down on the number of calls to
Widget.refresh()
andFont()
. By my count, when running the core test suite, font creation dropped from 110 to 42, and widget refreshes from 129 to 17.BaseStyle
gains abatch_apply
context manager in which all calls toapply()
are aggregated. This is used by:BaseStyle.update()
directional_property
(and eventuallycomposite_property
)__init__
; there's never an applicator present then, soapply()
is a no-op anyway.apply
and an inner_apply
.apply
is defined inBaseStyle
, and handles the logic of checking for an applicator and deciding whether to batch the requested name or call_apply
.Font
, or callrefresh()
more than once per call.apply()
, applying all possible style properties._batched_names
set doesn't need to be expanded into multiple positional arguments and then recreated as a set within the method.validated_property
always callsapply
on delete, even if the value being deleted is equal to the initial value, so I added a check there (and tested it).I also combined/parametrized the existing tests for:
test_property_with_explicit_const
test_property_with_explicit_value
test_property_with_explicit_none
test_property_with_implicit_default
I realize this changes the API of Travertino, in terms of what its subclass is supposed to override — but that's the only change. (Except that
apply()
goes back to accepting only a single name, but nothing was written yet that called it with multiple.) And it's still backwards compatible with Toga < 0.5, because existing Toga defines its ownPack.apply()
method and will completely ignore this; styles that it uses will simply never enter batched mode.PR Checklist: