gpt4 book ai didi

go - 在Go二进制文件中查找最大的导入包

转载 作者:行者123 更新时间:2023-12-01 22:44:30 25 4
gpt4 key购买 nike

当我使用go tool检查二进制文件时,我的项目有一个巨大的二进制文件(23MB,通常只有11MB大小),但它显示了项目中每个包的名称,而不是每个直接导入的包:

23 075 950 (23 MB)
go tool nm -sort size -size ApiServerQ | head -n 20

fb12c0 4874612 r runtime.pclntab
a741e0 669338 T github.com/aws/aws-sdk-go/aws/endpoints.init
87a200 305452 T github.com/xdg/stringprep.init
14d0c80 75600 D runtime.mheap_
14c0ba0 65744 D runtime.trace
fa0b60 38267 r runtime.findfunctab
149c6a0 30720 D crypto/ed25519/internal/edwards25519.base
62cd20 20993 T vendor/golang.org/x/crypto/chacha20poly1305.chacha20Poly1305Seal
faae40 20892 r runtime.typelink
4a4680 20413 T unicode.init
1497be0 19108 D vendor/golang.org/x/text/unicode/norm.decomps
1493120 19105 D golang.org/x/text/unicode/norm.decomps
628480 18589 T vendor/golang.org/x/crypto/chacha20poly1305.chacha20Poly1305Open
148f1a0 16256 D vendor/golang.org/x/net/idna.idnaValues
5c9080 16152 T crypto/sha512.blockAMD64
14bcce0 16064 D runtime.semtable
14e6c80 15384 D github.com/klauspost/compress/zstd.fsePredef
148b5a0 15360 D vendor/golang.org/x/text/unicode/bidi.bidiValues
485520 15154 T time.parse
859d20 14875 T go.mongodb.org/mongo-driver/x/mongo/driver/operation.(*IsMaster).Result

与我以前的一个项目(ScyllaDB)相比:
16 699 093 (16 MB)
go tool nm -sort size -size UserMicro | head -n 20
c94140 3345240 r runtime.pclntab
88fee0 625345 T github.com/aws/aws-sdk-go/aws/endpoints.init
1026020 65744 D runtime.trace
543070 32787 T github.com/yuin/gopher-lua/parse.yyParse
715c60 30757 T github.com/aerospike/aerospike-client-go.tryConcreteValue
ffeb60 30720 D crypto/ed25519/internal/edwards25519.base
c87080 27476 r runtime.findfunctab
64fae0 20993 T vendor/golang.org/x/crypto/chacha20poly1305.chacha20Poly1305Seal
499750 20065 T unicode.init
70d400 19890 T github.com/aerospike/aerospike-client-go.setValue
ffa0a0 19105 D vendor/golang.org/x/text/unicode/norm.decomps
64b240 18589 T vendor/golang.org/x/crypto/chacha20poly1305.chacha20Poly1305Open
c8e8e0 17060 r runtime.typelink
ff6120 16256 D vendor/golang.org/x/net/idna.idnaValues
5c09d0 16152 T crypto/sha512.blockAMD64
1022160 16064 D runtime.semtable
ff26a0 14976 D vendor/golang.org/x/text/unicode/bidi.bidiValues
59e0c0 14842 T github.com/yuin/gopher-lua.init
5eac20 14482 T crypto/sha256.block
5c7bc0 14174 T encoding/asn1.parseField

和其他较旧的版本(MemSQL + GORM):
15 438 537 (15 MB)
go tool nm -sort size -size MonolithI | head -n 20
b24500 3556591 r runtime.pclntab
ee3960 65744 D runtime.trace
ebbf60 30720 D crypto/ed25519/internal/edwards25519.base
b182e0 26236 r runtime.findfunctab
652aa0 20993 T vendor/golang.org/x/crypto/chacha20poly1305.chacha20Poly1305Seal
46f7b0 20065 T unicode.init
eb74a0 19105 D vendor/golang.org/x/text/unicode/norm.decomps
64e200 18589 T vendor/golang.org/x/crypto/chacha20poly1305.chacha20Poly1305Open
b1f6a0 16520 r runtime.typelink
eb3520 16256 D vendor/golang.org/x/net/idna.idnaValues
5f8a00 16152 T crypto/sha512.blockAMD64
edfaa0 16064 D runtime.semtable
eafaa0 14976 D vendor/golang.org/x/text/unicode/bidi.bidiValues
5a3300 14482 T crypto/sha256.block
5ffc90 14174 T encoding/asn1.parseField
4ba780 13913 T time.parse
8857e0 13733 T net/http.init
7dd940 13729 T github.com/go-sql-driver/mysql.parseDSNParams
7b21a0 12577 T github.com/kokizzu/gorm.(*Scope).buildCondition
768030 12202 T database/sql.convertAssignRows

另一个(PostgreSQL):
12 007 258 (12 MB)
go tool nm -sort size -size MonolithYOD | head -n 20
9914a0 2696675 r runtime.pclntab
c6d0c0 65744 D runtime.trace
4667d0 22868 T unicode.init.ializers
604f00 20993 T internal/x/crypto/chacha20poly1305.chacha20Poly1305Seal
987a40 19967 r runtime.findfunctab
c4c340 19105 D internal/x/text/unicode/norm.decomps
74bb00 19020 T github.com/tdewolff/minify/css.init.ializers
600660 18589 T internal/x/crypto/chacha20poly1305.chacha20Poly1305Open
c483c0 16256 D internal/x/net/idna.idnaValues
7a4de0 16186 T github.com/nfnt/resize.Resize
5bc930 16152 T crypto/sha512.blockAMD64
c69200 16064 D runtime.semtable
7a8d20 14984 T github.com/nfnt/resize.resizeNearest
5c4000 14964 T encoding/asn1.parseField
c44ac0 14592 D internal/x/text/unicode/bidi.bidiValues
55abc0 14482 T crypto/sha256.block
6f7e10 13890 T net/http.init.ializers
7bbb40 13555 T image/png.(*decoder).readImagePass
98d680 12544 r runtime.typelink
4d9bb0 12353 T encoding/json.(*decodeState).literalStore

另一个(PostgreSQL):
14 127 727 (14 MB)
go tool nm -sort size -size MonolithL | head -n 20
a94080 2899496 r runtime.pclntab
e095e0 75600 D runtime.mheap_
df9500 65744 D runtime.trace
73a9c0 35788 T github.com/tdewolff/minify/css.(*cssMinifier).minifyProperty
d8e380 30720 D crypto/ed25519/internal/edwards25519.base
845d10 26470 T github.com/golang/freetype/truetype.(*hinter).run
744510 25126 T github.com/tdewolff/minify/css.init
a895c0 23278 r runtime.findfunctab
60a110 20993 T vendor/golang.org/x/crypto/chacha20poly1305.chacha20Poly1305Seal
472ff0 20413 T unicode.init
d898c0 19108 D vendor/golang.org/x/text/unicode/norm.decomps
605870 18589 T vendor/golang.org/x/crypto/chacha20poly1305.chacha20Poly1305Open
d85940 16256 D vendor/golang.org/x/net/idna.idnaValues
5ba1e0 16152 T crypto/sha512.blockAMD64
df5640 16064 D runtime.semtable
7cb220 16012 T github.com/nfnt/resize.Resize
d81d40 15360 D vendor/golang.org/x/text/unicode/bidi.bidiValues
4879e0 15154 T time.parse
7cf0b0 14806 T github.com/nfnt/resize.resizeNearest
56b880 14482 T crypto/sha256.block

问题是,哪个软件包导致此膨胀?因为在没有外部CI / CD的情况下(甚至在upx和ldflags-s-w之后),或者是间接导入那个大程序包的项目的直接导入中的哪一个,将二进制文件上载到服务器还是需要一些时间?

已经尝试过 gofat,但是没有显示正确的软件包名称(它显示了混淆的软件包名称),还尝试了 goweight,但是它显示了 exit status 1

最佳答案

没关系,goweight解决了这个问题,显然我之前在错误的目录中运行了goweight。我还发现,由redis.v7导入的aws-sdk-gooverseer/fetcher(由depth检查)是罪魁祸首。

goweight . | head -n 20
8.7 MB github.com/go-redis/redis/v7
7.3 MB github.com/aws/aws-sdk-go/service/s3
3.9 MB net/http
3.8 MB runtime
3.3 MB github.com/gocql/gocql
2.8 MB github.com/aws/aws-sdk-go/aws/endpoints
2.5 MB github.com/valyala/fasthttp
1.9 MB go.mongodb.org/mongo-driver/mongo
1.8 MB net
1.8 MB crypto/tls
1.5 MB go.mongodb.org/mongo-driver/x/mongo/driver/operation
1.5 MB golang.org/x/sys/unix
1.4 MB reflect
1.2 MB github.com/xdg/stringprep
1.2 MB go.mongodb.org/mongo-driver/bson/bsoncodec
1.2 MB go.mongodb.org/mongo-driver/x/mongo/driver
1.1 MB go.mongodb.org/mongo-driver/bson/bsonrw
1.0 MB github.com/klauspost/compress/zstd
998 kB math/big
916 kB go.mongodb.org/mongo-driver/x/mongo/driver/topology
depth . | less
│ ├ github.com/jpillora/overseer/fetcher
│ │ ├ compress/gzip
│ │ ├ encoding/json
...
│ │ ├ net/http
│ │ ├ os
│ │ ├ github.com/aws/aws-sdk-go/aws


更新降级为 redis.v5并更新为 latest监督程序后,该监督程序删除了aws-sdk,还删除了gocqlx,它减少到18MB(如果使用ldflags-s-w,则减少到13MB;如果使用upx,则减少到4MB)
goweight . | head -n 20
3.9 MB net/http
3.8 MB runtime
3.0 MB gopkg.in/redis.v5
2.5 MB github.com/valyala/fasthttp
1.9 MB go.mongodb.org/mongo-driver/mongo
1.8 MB net
1.8 MB crypto/tls
1.5 MB go.mongodb.org/mongo-driver/x/mongo/driver/operation
1.5 MB golang.org/x/sys/unix
1.4 MB reflect
1.2 MB github.com/xdg/stringprep
1.2 MB go.mongodb.org/mongo-driver/bson/bsoncodec
1.2 MB go.mongodb.org/mongo-driver/x/mongo/driver
1.1 MB go.mongodb.org/mongo-driver/bson/bsonrw
1.0 MB github.com/klauspost/compress/zstd
998 kB math/big
916 kB go.mongodb.org/mongo-driver/x/mongo/driver/topology
847 kB syscall
828 kB go.mongodb.org/mongo-driver/x/bsonx
802 kB gopkg.in/mgo.v2/internal/json

关于go - 在Go二进制文件中查找最大的导入包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60886637/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com