On Sat, May 18, 2019 at 6:01 AM Tong Sun <suntong...@gmail.com> wrote:
>
> On Saturday, May 18, 2019 at 1:52:43 AM UTC-4, Ian Lance Taylor wrote:
>>
>> On Fri, May 17, 2019 at 9:12 PM Tong Sun <sunto...@gmail.com> wrote:
>> >
>> > How efficient Go linker is in detecting unused things (e.g., functions) in 
>> > a package during build and remove them from the compiled binary?
>> >
>> > To extremely simplify the case, say
>> >
>> > - I have a package that contains 10 individual functions, and each of them 
>> > will compile to 10K in binary size.
>> > - Then a program calls one single function from such package.
>> >
>> > Will the compiled binary executable be 10K more in size, because of 
>> > calling that one single function, or 100K more?
>> >
>> > I.e., will using a tiny portion of a big package cost me the whole big 
>> > package in compiled binary size, or only the tiny portion that I used?
>>
>> The linker will discard all unused functions and variables, but will
>> not discard unused methods.
>
>
>
> Thanks, Ian
>
> So in other words, if a package A that I'm using is importing 10 other 
> packages, and as long as any of the packages' methods are used within package 
> A's methods, all related methods from those 10 other packages will be 
> compiled & included in the binary executable, right?
>
> E.g., if I'm using a package just for CLI processing, however if the package 
> is doing some funky processing in its methods that use packages of net, 
> net/http, net/url, all related methods from net, net/http, net/url will end 
> up within my binary executable, right?

The details matter, and of course methods are associated with specific
types rather than packages, but, in the general case, yes, that can
happen.

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcU8VTs750TurABx6Hs5saRL%2BRmgvmUQGGb91mv0CdrQRQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to