Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize blink::Vector special constructors and assign()
In crrev.com/c/6181046, the following blink::Vector constructors were combined to call blink::Vector::assign: 1. Vector(vector with different inline capacity) 2. Vector(same vector type, projection) 3. Vector(vector with different inline capacity, projection) 4. Vector(range) blink::Vector::assign calls reserve (in GCForbiddenScope) and base::ranges::transform(back_inserter), which has lower performance than the original UinitializedCopy(). Optimizations: - For #1, add back the original code which can use memcpy when possible. - For #2, #3, #4, call a new function TypeOperations::UninitializedTransform() (which is basically equivalent to TypeOperations::UninitializedCopy() before crrev.com/c/6181046, but accepts generic input iterator), instead of assign(). - For assign(), remove GCForbiddenScope [1], and use UninitializedTransform() instead of transform(back_inserter). The differences between this CL and the version before crrev.com/c/6181046 are: - Vector(range) now uses optimized code path; - Vector::assign(range) is optimized. [1] About GCForbiddenScope: It was added to fix crbug.com/40448463. It prevents GC during reserve/resize to prevent the change of the input collection (if it's a hash table with WeakMember keys) during GC. Before that fix, the result vector might contain extra empty elements. With the new code, the size of the result vector is based on the final size of the range, so the original problem no longer exists. The capacity may be larger than necessary in rare cases, which is not a big deal. https://pinpoint-dot-chromeperf.appspot.com/job/16bf9884a10000 shows that removing GCForbiddenScope can improve performance of a benchmark by 5% (though the improvement will not apply with the final CL because the assign() code path is no longer used for that benchmark, which can get a greater improvement). Bug: 390461329 Change-Id: I152218d56ab93c44ca89f3397d96b0b7780edd6a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6185833 Reviewed-by: Kentaro Hara <[email protected]> Reviewed-by: Michael Lippautz <[email protected]> Commit-Queue: Xianzhu Wang <[email protected]> Cr-Commit-Position: refs/heads/main@{#1410367}
- Loading branch information