Make parsing SVG transform lists more efficient#42822
Conversation
|
EWS run on previous version of this PR (hash 3d5370c) Details |
There was a problem hiding this comment.
I think ListReplacement makes things a little bit more complicated. Why do not we make this function work in the replace mode as long as the type of the existingTransform matches the type of parsedTransform? And once the type differ, just call resize(itemIndex); and this will delete the remaining of all the existingTransforms
There was a problem hiding this comment.
I don't think that's possible, because some callers call it multiple times and expect the transforms to accumulate.
There was a problem hiding this comment.
It is not clear why we clearItems() when an error happens but only when ListReplacement::Replace. I understand you want to keep the existing behavior. But I think moving clearItems() back to SVGTransformList::parse(StringView value) make reading this function easier.
There was a problem hiding this comment.
Can be a for loop:
for (size_t itemIndex = 0; buffer.hasCharactersRemaining(); ++itemIndex)
There was a problem hiding this comment.
If calling clearItems(); was moved back to SVGTransformList::parse(StringView value), there is no need for put the parsing code in a lambda.
There was a problem hiding this comment.
I think this equivalent to
if (existingTransform && parsedTransform.get() != existingTransform.get()) {
There was a problem hiding this comment.
Instead of adding ASSERT to each switch case, we can add one ASSERT at the beginning
ASSERT_IMPLIES(reusableValue, type == reusableValue->value().type());
There was a problem hiding this comment.
Should we use the same name the caller passes above? reusableValue -> existingTransform?
Or at least do not use Value in the name to not confuse it with SVGTransformValue. reusableValue -> reusableTransform?
3d5370c to
96b298f
Compare
|
EWS run on previous version of this PR (hash 96b298f) Details |
96b298f to
74da465
Compare
|
EWS run on previous version of this PR (hash 74da465) Details |
There was a problem hiding this comment.
Good that you caught this case. But itemIndex < m_items.size() implies currentListReplacement == ListReplacement::Replace i.e. it is not possible that the first clause is true and the second one is false.
74da465 to
09770fb
Compare
|
EWS run on current version of this PR (hash 09770fb) Details |
https://bugs.webkit.org/show_bug.cgi?id=290192 rdar://147591008 Reviewed by Said Abou-Hallawa. Content that animates SVG transforms will often keep the same list of transform operations, but just change the values. Currently, `SVGTransformList::parse()` implements this by clearing the list and re-build it, but this involves a lot of object churn: each SVGTransform is heap-allocated, and itself has a heap-allocated SVGMatrix. In addition, `detach()` and `attach()` have overhead. Make this more efficient by re-using the existing SVGTransforms when possible. Do this by moving the list management into `SVGTransformList::parseGeneric()`. Callers of `parse()` expect the list to be preserved between calls, so the `ListReplacement` argument controls that behavior. Pass the existing object to `SVGTransformable::parseTransform` if the type matches; we compare that with the return value to know if the item was re-used. If not, we go back to appending. Well tested by existing SVG tests. * Source/WebCore/svg/SVGTransformList.cpp: (WebCore::SVGTransformList::parseGeneric): (WebCore::SVGTransformList::parse): * Source/WebCore/svg/SVGTransformList.h: * Source/WebCore/svg/SVGTransformable.cpp: (WebCore::parseTransformGeneric): (WebCore::SVGTransformable::parseTransform): (WebCore::parseTransformValueGeneric): Deleted. (WebCore::SVGTransformable::parseTransformValue): Deleted. * Source/WebCore/svg/SVGTransformable.h: Canonical link: https://commits.webkit.org/292545@main
09770fb to
bef74b7
Compare
|
Committed 292545@main (bef74b7): https://commits.webkit.org/292545@main Reviewed commits have been landed. Closing PR #42822 and removing active labels. |
bef74b7
09770fb