Giter Site home page Giter Site logo

Comments (3)

aykevl avatar aykevl commented on May 9, 2024

I don't think it is actually possible to calculate cap() on demand, because it can be set to an arbitrary value: consider slice[:5:7], which sets len to 5 and cap to 7 no matter what they were before.

In general, I think the compiler will be able to optimize cap away in trivial cases where it is never used (no append or cap call). This will probably improve once I get around to splitting the slice struct into independent variables in function calls etc. which LLVM is better at optimizing away.

from tinygo.

deadprogram avatar deadprogram commented on May 9, 2024

Is this issue still relevant given all of the internal changes to TinyGo, or should it be closed?

from tinygo.

aykevl avatar aykevl commented on May 9, 2024

I don't think there is anything I can do here. I don't see a way to perform this optimization while still adhering to the Go language specification. Additionally, slices in local variables and function parameters are easily optimized by LLVM: function parameters are split up in #20 and local variables are split up by LLVM. Unnecessary copies are usually avoided by dead code elimination passes and the deadargelim pass. This means that the cap part of a slice is often already eliminated.

If there is something I'm missing I'd like to know about it. For now, I'm going to close the issue.

from tinygo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.