Internal Development
Intended for the development of WTX
although some tips might be useful for your projects.
Size constraints
A large enum aggressively used in several places can cause a negative runtime impact. In fact, this is so common that the community created several lints to prevent such a scenario.
Some real-world use-cases and associated benchmarks.
- https://ziglang.org/download/0.8.0/release-notes.html#Reworked-Memory-Layout
- https://github.com/rust-lang/rust/pull/100441
- https://github.com/rust-lang/rust/pull/95715
That is why WTX
has an enforced Error
enum size of 24 bytes that will hopefully get smaller in future and that is also the reason why WTX
has so many bare variants.
Profiling
Uses the h2load
benchmarking tool (https://nghttp2.org/documentation/h2load-howto.html) and the h2load
internal binary (https://github.com/c410-f3r/wtx/blob/main/wtx-instances/src/bin/h2load.rs) for illustration purposes.
Compilation time / Size
cargo-bloat
: Finds out what takes most of the space in executables.
cargo bloat --bin h2load --features h2load | head -20
cargo-llvm-lines
: Measures the number and size of instantiations of each generic function in a program.
CARGO_PROFILE_RELEASE_LTO=fat cargo llvm-lines --bin h2load --features h2load --package wtx-instances --release | head -20
Performance
Prepare the executables in different terminals.
h2load -c100 --log-file=/tmp/h2load.txt -m10 -n10000 --no-tls-proto=h2c http://localhost:9000
cargo build --bin h2load --features h2load --profile profiling --target x86_64-unknown-linux-gnu
samply
: Command line CPU profiler.
cargo build --bin h2load --features h2load --profile profiling --target x86_64-unknown-linux-gnu
samply record ./target/x86_64-unknown-linux-gnu/profiling/h2load
callgrind
: Gives global, per-function, and per-source-line instruction counts and simulated cache and branch prediction data.
valgrind --tool=callgrind --dump-instr=yes --collect-jumps=yes --simulate-cache=yes ./target/x86_64-unknown-linux-gnu/profiling/h2load