What are the best practices for handling slices and their performance in Mojo?

I'm trying to better understand how slices work in Mojo, particularly regarding performance. From what I've seen, slices in languages like Python can introduce overhead in high-performance scenarios. In Mojo, are there any specific optimizations for slices, or situations where their use should be avoided? Is there any comparison between slices and other approaches (like pointers or arrays) in terms of efficiency?
2 Replies
eggsquad
eggsquad2mo ago
Taking a slice from a List will result in a copy of the returned items, if you wish to avoid said copy you can use a Span instead
sora
sora2mo ago
Slices in Mojo are just pointer-length pair, you should expect performance similar to C++ span.

Did you find this page helpful?