{"id":21423830,"url":"https://github.com/ossystems/web-client-server-binary-size-benchmark-rs","last_synced_at":"2025-07-14T08:31:29.223Z","repository":{"id":41469249,"uuid":"251719948","full_name":"OSSystems/web-client-server-binary-size-benchmark-rs","owner":"OSSystems","description":"Benchmark of different combinations of server and client crates in Rust to check what offers lower binary size","archived":false,"fork":false,"pushed_at":"2020-07-06T15:30:52.000Z","size":471,"stargazers_count":11,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-08T05:13:19.886Z","etag":null,"topics":["benchmark","binary-size","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/OSSystems.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-03-31T20:11:58.000Z","updated_at":"2025-03-26T18:10:09.000Z","dependencies_parsed_at":"2022-08-25T10:40:31.700Z","dependency_job_id":null,"html_url":"https://github.com/OSSystems/web-client-server-binary-size-benchmark-rs","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/OSSystems/web-client-server-binary-size-benchmark-rs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OSSystems%2Fweb-client-server-binary-size-benchmark-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OSSystems%2Fweb-client-server-binary-size-benchmark-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OSSystems%2Fweb-client-server-binary-size-benchmark-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OSSystems%2Fweb-client-server-binary-size-benchmark-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OSSystems","download_url":"https://codeload.github.com/OSSystems/web-client-server-binary-size-benchmark-rs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OSSystems%2Fweb-client-server-binary-size-benchmark-rs/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265262601,"owners_count":23736427,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["benchmark","binary-size","rust"],"created_at":"2024-11-22T21:18:25.337Z","updated_at":"2025-07-14T08:31:28.869Z","avatar_url":"https://github.com/OSSystems.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Web-Client-Server Binary-Size Benchmark - Rust\n\nThis small benchmark is intended to compare how different combinations of HTTP\nClient and HTTP Server will affect the binary size of applications.\n\nThe base application we will be covering here has some basic requirements that\nare based on needs that we have for our real-world app.\nThe app also have some usage of OpenSSL,\nwhich is also a requirement of our app,\nas we need to handle RSA signature validation,\nso if any implementation make use of code defined there will have a valid advantage.\nThis are the requirement for all binaries implementation:\n\n* A running server to respond to requests from a local client;\n* A client to make local requests to the server;\n* A second client to make requests to a remote server;\n* Clients needs to handle:\n  * JSON serialization and deserialization;\n  * HTTP Header extraction;\n* Share state between the Remote Client and the App;\n* Asynchronous type signature;\n\n## Implementations rules\n\nThe [RULES.md](RULES.md) file describe how implementations should be made.\n\n## Contestants\n\n| Implementation  |   Server  | Client  |\n|:---------------:|:---------:|:-------:|\n| dummy           | -         | -       |\n| actix\\_full     | actix-web | awc     |\n| actix\\_reqwest  | actix-web | reqwest |\n| gotham\\_reqwest | gotham    | reqwest |\n| hyper\\_full     | hyper     | hyper   |\n| hyper\\_reqwest  | hyper     | reqwest |\n| warp\\_surf      | warp      | surf    |\n| tide\\_surf      | tide      | surf    |\n| warp\\_reqwest   | warp      | reqwest |\n\n## Data Collected\n\nThe total binary size and,\nmainly,\nthe distribution of the size contribution by crate is generated using [cargo bloat](https://github.com/RazrFalcon/cargo-bloat).\nAlthough not 100% precise,\nwe believe it's estimations are reliable enough for the data we've collected and analysed.\n\nFor all contestants in this benchmark we have collected information with different build options.\nAll builds are generated with *cargo*'s release build plus a combination of the following flags:\n\n|  Parameter    | Values             |\n|:-------------:|:------------------:|\n| [Optimization]  | [0, 1, 2, 3, s, z] |\n| [LTO]           | [thin, fat]        |\n| [Codegen Units] | [1, 16]            |\n\n[Optimization]: https://doc.rust-lang.org/cargo/reference/profiles.html#opt-level\n[LTO]: https://doc.rust-lang.org/cargo/reference/profiles.html#lto\n[Codegen Units]: https://doc.rust-lang.org/cargo/reference/profiles.html#codegen-units\n\n## Analysis and Results\n\nThe main lessons we've learned from checking the results of our benchmark can be summarised in three points:\n\n1. [Don't be afraid of using micro-dependencies](#dont-fear-micro-dependencies);\n2. [Set some extra optimization flags](#set-the-optimization-flags);\n3. [The most suitable pair for us is tide-surf](#tide-surf-the-current-winner);\n\nHere on the repository README.md we will be presenting a feel graphs in order to illustrate our analysis;\nthe full data, as well as some more interactive graphs,\nare available at [this shinyapp](https://jonathas-conceicao.shinyapps.io/web-client-server-binary-size-benchmark-rs/) for anyone who wants to have a more complete view of it.\n\n### Don't fear micro-dependencies\n\nIt's easy to see how having multiple dependencies can largely affect build time of our projects.\nBut when it comes to binary size, the data we collected tells us that there is little to worry there.\nTake for example the following plot for the major crates on our larger contestant, `actix_full`:\n\n![actix\\_full crate size](fixtures/actix_full_crates_size.svg)\nFigure: *`actix_full` with top crates highlighted ([Interactive graph](https://jonathas-conceicao.shinyapps.io/web-client-server-binary-size-benchmark-rs/)).*\n\nEven after optimization,\nthe plot shows that only 5 of it's total 76 crates accounts for over 50% of it's binary size.\n\nThe following box plot show the distribution of all crates size across all projects.\nThis shows that the vast majority of dependencies contribute very little to the total binary size.\n\n![crates distribution](fixtures/crates_dist.svg)\nFigure: *Crates size distribution ([Interactive graph](https://jonathas-conceicao.shinyapps.io/web-client-server-binary-size-benchmark-rs/)).*\n\nTherefore we find it much more meaningful to choose carefully the core dependency for or apps,\nthen it is to trying to minimise the total number of dependencies.\n\n### Set the optimization flags\n\nBinary Size optimization is not the default goal that the rust compiler aims to achieve,\nbut it can get there if the developer requests it.\nThe following plot shows how different optimization options affects the Binary Size on our smaller contestant, `tide_surf`.\n\n![optimization plot for tide\\_surf](fixtures/optimization_tide_surf.svg)\nFigure: *Optimization parameters on `tide_surf` ([Interactive graph](https://jonathas-conceicao.shinyapps.io/web-client-server-binary-size-benchmark-rs/)).*\n\nCargo's default release build uses Optimization Level 3, LTO Thin and 16 Codegen Units.\nComparing that to the smaller binary we've generated we can see a improvement of around 40%.\nAll other projects have shown better results when using Optimization Z, LTO Fat and 1 Codegen Unit,\nso that will be our default flags for smaller binary size.\n\n### tide-surf, the current winner\n\nThe [async-std](https://github.com/async-rs/async-std) based pair, `tide-surf`,\nis our new choice of HTTP client-server pair for embedded applications.\nDespite having a high level API, it still had better results that more lower level APIs such as `hyper_full`.\n\nIf we were to choose a pair that's built fully on top of [tokio](https://github.com/tokio-rs/tokio),\nanother of the main runtimes for rust's async ecosystem,\nwe will definitely be considering [warp](https://github.com/seanmonstar/warp).\nThe crate has presented a small Binary Size overhead over [hyper](https://github.com/hyperium/hyper) for a much more simpler API for building HTTP servers.\n\n![projects sizes](fixtures/projects_sizes.svg)\nFigure: *All projects size ([Interactive graph](https://jonathas-conceicao.shinyapps.io/web-client-server-binary-size-benchmark-rs/))*\n\n## Contributing\n\nNew pairs of applications are welcome provided they meet the rules specified to compete.\n\n## License\n\nLicensed under Apache License, Version 2.0 (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fossystems%2Fweb-client-server-binary-size-benchmark-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fossystems%2Fweb-client-server-binary-size-benchmark-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fossystems%2Fweb-client-server-binary-size-benchmark-rs/lists"}