[SR-10667] Optimise chained SubSequence producing methods into fewer calls #53066
Labels
compiler
The Swift compiler itself
good first issue
Good for newcomers
improvement
performance
SILGen
Area → compiler: The SIL generation stage
Additional Detail from JIRA
md5: 3d2eff2a03f31963319181f67fe2b19a
Issue Description:
This code (on
BidirectionalCollection
) is nice and concise, but it's not efficient:It could be optimised by the compiler into something like this:
At @jckarter's suggestion this could be implemented with
@_semantics
similar to some existing optimisations on Array and String. An example of this is here: #5978.There's a lot of permutations for
suffix, prefix, dropFirst, dropLast, first, last
, etc. so adding a special case for every one would be excessive. Ideally there is a more generic approach to pattern match and reduce these kinds of expressions. This might be done by having multiple small patterns, that can be combined to reduce the chain of calls iteratively.Here are some ideas for further optimisations:
The text was updated successfully, but these errors were encountered: