Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

バイナリサイズ最適化 #62

Open
riii111 opened this issue Oct 30, 2024 · 0 comments
Open

バイナリサイズ最適化 #62

riii111 opened this issue Oct 30, 2024 · 0 comments
Assignees
Labels
backend enhancement New feature or request

Comments

@riii111
Copy link
Owner

riii111 commented Oct 30, 2024

対象

1. image

サポートする機能を限定。例↓

[dependencies]
image = { version = "0.24", default-features = false, features = ["jpeg", "png", "gif"] }

2. mongodb

zstd圧縮やAWS認証を無効化。例↓

# After
mongodb = { version = "2.8", default-features = false, features = [
    "async-std-runtime",  # または "tokio-runtime"
    "bson-uuid-0_8",     # UUIDを使用する場合
    "bson-chrono-0_4"    # DateTimeを使用する場合
] }

3. aws-sdk-s3

基本的なS3操作のみとし、認証機能とかは削除

aws-sdk-s3 = { version = "0.28", default-features = false, features = [
    "rt-tokio",        # Tokioランタイムを使用
    "native-tls",      # TLS実装
    "behavior-version-latest"
] }

4. actix-web

以下みたいな感じで修正

actix-web = { version = "4.0", features = [
    "compress-brotli",    # 必要な圧縮アルゴリズム
    "compress-gzip",
    "cookies",            # クッキーを使用する場合
    "secure-cookies"      # セキュアクッキーを使用する場合
] }

補足

CI/CDで行ったバイナリサイズの調査結果

 File  .text      Size Crate
 5.0%  12.9%    2.8MiB mongodb
 4.6%  12.0%    2.6MiB std
 3.3%   8.4%    1.9MiB openssl_sys
 2.4%   6.2%    1.4MiB [Unknown]
 1.9%   5.0%    1.1MiB rav1e
 1.9%   4.8%    1.1MiB bson
 1.7%   4.5% 1013.1KiB aws_smithy_runtime
 1.6%   4.2%  954.4KiB aws_sdk_s3
 1.4%   3.6%  810.4KiB ravif
 1.2%   3.2%  721.8KiB devtrackr_api
 0.8%   2.0%  449.6KiB h2
 0.6%   1.6%  368.0KiB regex_automata
 0.6%   1.6%  360.6KiB actix_web
 0.6%   1.4%  319.7KiB redis
 0.5%   1.3%  284.4KiB rustls
 0.4%   1.1%  257.6KiB tokio
 0.4%   1.1%  246.8KiB exr
 0.4%   1.1%  238.5KiB trust_dns_proto
 0.4%   1.0%  236.0KiB serde
 0.4%   1.0%  228.8KiB image
 7.9%  20.4%    4.5MiB And 183 more crates. Use -n N to show more.
38.8% 100.0%   22.0MiB .text section size, the file size is 56.8MiB

Note: numbers above are a result of guesswork. They are not 100% correct and never will be.
    Finished `release` profile [optimized] target(s) in 0.25s
    Analyzing target/release/devtrackr_api

 File  .text     Size              Crate Name
 0.6%   1.5% 329.7KiB        openssl_sys ossl_aes_gcm_encrypt_avx512
 0.6%   1.5% 329.7KiB        openssl_sys ossl_aes_gcm_decrypt_avx512
 0.4%   1.0% 214.5KiB         aws_sdk_s3 aws_sdk_s3::config::endpoint::internals::resolve_endpoint
 0.1%   0.2%  41.2KiB      devtrackr_api devtrackr_api::main::{{closure}}
 0.1%   0.2%  39.3KiB            mongodb mongodb::client::options::ClientOptions::parse_uri::{{closure}}
 0.1%   0.2%  34.4KiB aws_smithy_runtime aws_smithy_runtime::client::orchestrator::try_attempt::{{closure}}::{{closure}}
 0.1%   0.2%  34.3KiB         aws_sdk_s3 aws_smithy_runtime::client::orchestrator::try_attempt::{{closure}}::{{closure}}
 0.1%   0.2%  34.3KiB         aws_sdk_s3 aws_smithy_runtime::client::orchestrator::try_attempt::{{closure}}::{{closure}}
 0.1%   0.2%  34.3KiB         aws_sdk_s3 aws_smithy_runtime::client::orchestrator::try_attempt::{{closure}}::{{closure}}
 0.1%   0.2%  34.3KiB aws_smithy_runtime aws_smithy_runtime::client::orchestrator::try_attempt::{{closure}}::{{closure}}
 0.1%   0.2%  34.3KiB aws_smithy_runtime aws_smithy_runtime::client::orchestrator::try_attempt::{{closure}}::{{closure}}
 0.1%   0.1%  30.6KiB       jpeg_decoder jpeg_decoder::decoder::Decoder<R>::decode_internal
 0.0%   0.1%  28.9KiB              rav1e rav1e::rdo::rdo_loop_decision
 0.0%   0.1%  28.9KiB              rav1e rav1e::rdo::rdo_loop_decision
 0.0%   0.1%  27.0KiB      devtrackr_api devtrackr_api::config::db_index::create_indexes::{{closure}}
 0.0%   0.1%  26.9KiB                 h2 h2::codec::framed_read::decode_frame
 0.0%   0.1%  26.1KiB aws_smithy_runtime h2::proto::connection::Connection<T,P,B>::poll
 0.0%   0.1%  25.6KiB aws_smithy_runtime aws_smithy_runtime::client::orchestrator::try_op::{{closure}}::{{closure}}
 0.0%   0.1%  25.0KiB         aws_sdk_s3 aws_smithy_runtime::client::orchestrator::try_op::{{closure}}::{{closure}}
 0.0%   0.1%  24.9KiB aws_smithy_runtime aws_smithy_runtime::client::orchestrator::try_op::{{closure}}::{{closure}}
35.8%  92.3%  20.3MiB                    And 44650 smaller methods. Use -n N to show more.
38.8% 100.0%  22.0MiB                    .text section size, the file size is 56.8MiB
@riii111 riii111 added enhancement New feature or request backend labels Oct 30, 2024
@riii111 riii111 self-assigned this Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant