[{"data":1,"prerenderedAt":2459},["ShallowReactive",2],{"page-\u002Frust\u002F31-performance":3},{"id":4,"title":5,"body":6,"description":16,"extension":2453,"meta":2454,"navigation":116,"path":2455,"seo":2456,"stem":2457,"__hash__":2458},"content\u002Frust\u002F31-performance.md","31 — Performance, Profiling & Optimization",{"type":7,"value":8,"toc":2392},"minimark",[9,13,17,22,45,49,58,204,209,216,341,351,355,358,423,427,434,474,477,500,505,529,532,539,567,577,580,584,588,763,772,784,795,799,802,806,825,833,836,840,866,881,1003,1010,1018,1082,1089,1093,1114,1122,1193,1196,1200,1214,1218,1272,1280,1286,1297,1345,1348,1352,1476,1484,1569,1573,1656,1659,1663,1673,1681,1684,1688,1737,1746,1753,1798,1802,1805,2006,2013,2019,2056,2059,2063,2089,2092,2096,2271,2275,2298,2304,2317,2321,2352,2356,2385,2388],[10,11,5],"h1",{"id":12},"_31-performance-profiling-optimization",[14,15,16],"p",{},"Rust gives you C-level performance by default, but you can still write slow Rust. This chapter covers how to find and fix bottlenecks.",[18,19,21],"h2",{"id":20},"mindset","Mindset",[23,24,25,33,39],"ol",{},[26,27,28,32],"li",{},[29,30,31],"strong",{},"Don't optimize prematurely."," Write clear code; profile; optimize hot spots.",[26,34,35,38],{},[29,36,37],{},"Measure, measure, measure."," Intuition is often wrong.",[26,40,41,44],{},[29,42,43],{},"Iterate."," One change at a time; re-measure each time.",[18,46,48],{"id":47},"benchmarking","Benchmarking",[50,51,53,57],"h3",{"id":52},"cargo-bench-nightly",[54,55,56],"code",{},"cargo bench"," (nightly)",[59,60,62],"code-wrapper",{"language":61},"rust",[63,64,68],"pre",{"className":65,"code":66,"language":61,"meta":67,"style":67},"language-rust shiki shiki-themes github-light github-dark","#![feature(test)]\nextern crate test;\nuse test::Bencher;\n\n#[bench]\nfn bench_add(b: &mut Bencher) {\n    b.iter(|| test::black_box(2) + test::black_box(2));\n}\n","",[54,69,70,79,92,111,118,124,148,198],{"__ignoreMap":67},[71,72,75],"span",{"class":73,"line":74},"line",1,[71,76,78],{"class":77},"ssxIu","#![feature(test)]\n",[71,80,82,86,89],{"class":73,"line":81},2,[71,83,85],{"class":84},"svdQ7","extern",[71,87,88],{"class":84}," crate",[71,90,91],{"class":77}," test;\n",[71,93,95,98,102,105,108],{"class":73,"line":94},3,[71,96,97],{"class":84},"use",[71,99,101],{"class":100},"sIsaT"," test",[71,103,104],{"class":84},"::",[71,106,107],{"class":100},"Bencher",[71,109,110],{"class":77},";\n",[71,112,114],{"class":73,"line":113},4,[71,115,117],{"emptyLinePlaceholder":116},true,"\n",[71,119,121],{"class":73,"line":120},5,[71,122,123],{"class":77},"#[bench]\n",[71,125,127,130,133,136,139,142,145],{"class":73,"line":126},6,[71,128,129],{"class":84},"fn",[71,131,132],{"class":100}," bench_add",[71,134,135],{"class":77},"(b",[71,137,138],{"class":84},":",[71,140,141],{"class":84}," &mut",[71,143,144],{"class":100}," Bencher",[71,146,147],{"class":77},") {\n",[71,149,151,154,157,160,163,166,168,170,173,175,179,182,185,187,189,191,193,195],{"class":73,"line":150},7,[71,152,153],{"class":77},"    b",[71,155,156],{"class":84},".",[71,158,159],{"class":100},"iter",[71,161,162],{"class":77},"(",[71,164,165],{"class":84},"||",[71,167,101],{"class":100},[71,169,104],{"class":84},[71,171,172],{"class":100},"black_box",[71,174,162],{"class":77},[71,176,178],{"class":177},"snvgF","2",[71,180,181],{"class":77},") ",[71,183,184],{"class":84},"+",[71,186,101],{"class":100},[71,188,104],{"class":84},[71,190,172],{"class":100},[71,192,162],{"class":77},[71,194,178],{"class":177},[71,196,197],{"class":77},"));\n",[71,199,201],{"class":73,"line":200},8,[71,202,203],{"class":77},"}\n",[14,205,206,208],{},[54,207,172],{}," prevents the optimizer from constant-folding.",[50,210,212,215],{"id":211},"criterion-stable-recommended",[54,213,214],{},"criterion"," (stable, recommended)",[59,217,218],{"language":61},[63,219,221],{"className":65,"code":220,"language":61,"meta":67,"style":67},"use criterion::{criterion_group, criterion_main, Criterion};\n\nfn bench_fib(c: &mut Criterion) {\n    c.bench_function(\"fib 20\", |b| b.iter(|| fib(black_box(20))));\n}\n\ncriterion_group!(benches, bench_fib);\ncriterion_main!(benches);\n",[54,222,223,241,245,264,317,321,325,333],{"__ignoreMap":67},[71,224,225,227,230,232,235,238],{"class":73,"line":74},[71,226,97],{"class":84},[71,228,229],{"class":100}," criterion",[71,231,104],{"class":84},[71,233,234],{"class":77},"{criterion_group, criterion_main, ",[71,236,237],{"class":100},"Criterion",[71,239,240],{"class":77},"};\n",[71,242,243],{"class":73,"line":81},[71,244,117],{"emptyLinePlaceholder":116},[71,246,247,249,252,255,257,259,262],{"class":73,"line":94},[71,248,129],{"class":84},[71,250,251],{"class":100}," bench_fib",[71,253,254],{"class":77},"(c",[71,256,138],{"class":84},[71,258,141],{"class":84},[71,260,261],{"class":100}," Criterion",[71,263,147],{"class":77},[71,265,266,269,271,274,276,280,283,286,289,291,294,296,298,300,302,305,307,309,311,314],{"class":73,"line":113},[71,267,268],{"class":77},"    c",[71,270,156],{"class":84},[71,272,273],{"class":100},"bench_function",[71,275,162],{"class":77},[71,277,279],{"class":278},"sJ6F3","\"fib 20\"",[71,281,282],{"class":77},", ",[71,284,285],{"class":84},"|",[71,287,288],{"class":77},"b",[71,290,285],{"class":84},[71,292,293],{"class":77}," b",[71,295,156],{"class":84},[71,297,159],{"class":100},[71,299,162],{"class":77},[71,301,165],{"class":84},[71,303,304],{"class":100}," fib",[71,306,162],{"class":77},[71,308,172],{"class":100},[71,310,162],{"class":77},[71,312,313],{"class":177},"20",[71,315,316],{"class":77},"))));\n",[71,318,319],{"class":73,"line":120},[71,320,203],{"class":77},[71,322,323],{"class":73,"line":126},[71,324,117],{"emptyLinePlaceholder":116},[71,326,327,330],{"class":73,"line":150},[71,328,329],{"class":100},"criterion_group!",[71,331,332],{"class":77},"(benches, bench_fib);\n",[71,334,335,338],{"class":73,"line":200},[71,336,337],{"class":100},"criterion_main!",[71,339,340],{"class":77},"(benches);\n",[14,342,343,344,347,348,350],{},"In ",[54,345,346],{},"benches\u002Fmy_bench.rs",". Run with ",[54,349,56],{},". Criterion provides statistics, regressions, and HTML reports.",[50,352,354],{"id":353},"custom-benchmarks","Custom Benchmarks",[14,356,357],{},"For ad-hoc timing:",[59,359,360],{"language":61},[63,361,363],{"className":65,"code":362,"language":61,"meta":67,"style":67},"let start = std::time::Instant::now();\nwork();\nlet elapsed = start.elapsed();\n",[54,364,365,397,404],{"__ignoreMap":67},[71,366,367,370,373,376,379,381,384,386,389,391,394],{"class":73,"line":74},[71,368,369],{"class":84},"let",[71,371,372],{"class":77}," start ",[71,374,375],{"class":84},"=",[71,377,378],{"class":100}," std",[71,380,104],{"class":84},[71,382,383],{"class":100},"time",[71,385,104],{"class":84},[71,387,388],{"class":100},"Instant",[71,390,104],{"class":84},[71,392,393],{"class":100},"now",[71,395,396],{"class":77},"();\n",[71,398,399,402],{"class":73,"line":81},[71,400,401],{"class":100},"work",[71,403,396],{"class":77},[71,405,406,408,411,413,416,418,421],{"class":73,"line":94},[71,407,369],{"class":84},[71,409,410],{"class":77}," elapsed ",[71,412,375],{"class":84},[71,414,415],{"class":77}," start",[71,417,156],{"class":84},[71,419,420],{"class":100},"elapsed",[71,422,396],{"class":77},[18,424,426],{"id":425},"profiling","Profiling",[50,428,430,433],{"id":429},"perf-linux",[54,431,432],{},"perf"," (Linux)",[59,435,437],{"language":436},"bash",[63,438,441],{"className":439,"code":440,"language":436,"meta":67,"style":67},"language-bash shiki shiki-themes github-light github-dark","cargo build --release\nperf record -g .\u002Ftarget\u002Frelease\u002Fmy_app\nperf report\n",[54,442,443,454,467],{"__ignoreMap":67},[71,444,445,448,451],{"class":73,"line":74},[71,446,447],{"class":100},"cargo",[71,449,450],{"class":278}," build",[71,452,453],{"class":177}," --release\n",[71,455,456,458,461,464],{"class":73,"line":81},[71,457,432],{"class":100},[71,459,460],{"class":278}," record",[71,462,463],{"class":177}," -g",[71,465,466],{"class":278}," .\u002Ftarget\u002Frelease\u002Fmy_app\n",[71,468,469,471],{"class":73,"line":94},[71,470,432],{"class":100},[71,472,473],{"class":278}," report\n",[14,475,476],{},"For flamegraphs:",[59,478,479],{"language":436},[63,480,482],{"className":439,"code":481,"language":436,"meta":67,"style":67},"cargo install flamegraph\ncargo flamegraph\n",[54,483,484,494],{"__ignoreMap":67},[71,485,486,488,491],{"class":73,"line":74},[71,487,447],{"class":100},[71,489,490],{"class":278}," install",[71,492,493],{"class":278}," flamegraph\n",[71,495,496,498],{"class":73,"line":81},[71,497,447],{"class":100},[71,499,493],{"class":278},[50,501,503],{"id":502},"samply",[54,504,502],{},[59,506,507],{"language":436},[63,508,510],{"className":439,"code":509,"language":436,"meta":67,"style":67},"cargo install samply\nsamply record .\u002Ftarget\u002Frelease\u002Fmy_app\n",[54,511,512,521],{"__ignoreMap":67},[71,513,514,516,518],{"class":73,"line":74},[71,515,447],{"class":100},[71,517,490],{"class":278},[71,519,520],{"class":278}," samply\n",[71,522,523,525,527],{"class":73,"line":81},[71,524,502],{"class":100},[71,526,460],{"class":278},[71,528,466],{"class":278},[14,530,531],{},"Samply gives a web UI with call trees and source-level annotations.",[50,533,535,538],{"id":534},"instruments-macos",[54,536,537],{},"Instruments"," (macOS)",[59,540,541],{"language":436},[63,542,544],{"className":439,"code":543,"language":436,"meta":67,"style":67},"xcrun xctrace record --template \"Time Profiler\" --launch .\u002Ftarget\u002Frelease\u002Fmy_app\n",[54,545,546],{"__ignoreMap":67},[71,547,548,551,554,556,559,562,565],{"class":73,"line":74},[71,549,550],{"class":100},"xcrun",[71,552,553],{"class":278}," xctrace",[71,555,460],{"class":278},[71,557,558],{"class":177}," --template",[71,560,561],{"class":278}," \"Time Profiler\"",[71,563,564],{"class":177}," --launch",[71,566,466],{"class":278},[50,568,570,282,573,576],{"id":569},"dtrace-vtune-advanced",[54,571,572],{},"dtrace",[54,574,575],{},"vtune"," (advanced)",[14,578,579],{},"For deeper hardware analysis (cache misses, branch mispredicts).",[18,581,583],{"id":582},"optimization-techniques","Optimization Techniques",[50,585,587],{"id":586},"_1-avoid-unnecessary-allocation","1. Avoid Unnecessary Allocation",[59,589,590],{"language":61},[63,591,593],{"className":65,"code":592,"language":61,"meta":67,"style":67},"\u002F\u002F Bad: allocates per call\nfn process(items: &[u8]) -> Vec\u003Cu8> { items.iter().map(|x| x + 1).collect() }\n\n\u002F\u002F Good: caller provides buffer\nfn process_into(items: &[u8], out: &mut [u8]) {\n    for (i, x) in items.iter().enumerate() { out[i] = x + 1; }\n}\n",[54,594,595,601,679,683,688,720,759],{"__ignoreMap":67},[71,596,597],{"class":73,"line":74},[71,598,600],{"class":599},"sdCPZ","\u002F\u002F Bad: allocates per call\n",[71,602,603,605,608,611,613,616,619,622,625,628,631,634,636,639,641,643,646,648,651,653,655,658,660,663,665,668,671,673,676],{"class":73,"line":81},[71,604,129],{"class":84},[71,606,607],{"class":100}," process",[71,609,610],{"class":77},"(items",[71,612,138],{"class":84},[71,614,615],{"class":84}," &",[71,617,618],{"class":77},"[",[71,620,621],{"class":100},"u8",[71,623,624],{"class":77},"]) ",[71,626,627],{"class":84},"->",[71,629,630],{"class":100}," Vec",[71,632,633],{"class":77},"\u003C",[71,635,621],{"class":100},[71,637,638],{"class":77},"> { items",[71,640,156],{"class":84},[71,642,159],{"class":100},[71,644,645],{"class":77},"()",[71,647,156],{"class":84},[71,649,650],{"class":100},"map",[71,652,162],{"class":77},[71,654,285],{"class":84},[71,656,657],{"class":77},"x",[71,659,285],{"class":84},[71,661,662],{"class":77}," x ",[71,664,184],{"class":84},[71,666,667],{"class":177}," 1",[71,669,670],{"class":77},")",[71,672,156],{"class":84},[71,674,675],{"class":100},"collect",[71,677,678],{"class":77},"() }\n",[71,680,681],{"class":73,"line":94},[71,682,117],{"emptyLinePlaceholder":116},[71,684,685],{"class":73,"line":113},[71,686,687],{"class":599},"\u002F\u002F Good: caller provides buffer\n",[71,689,690,692,695,697,699,701,703,705,708,710,712,715,717],{"class":73,"line":120},[71,691,129],{"class":84},[71,693,694],{"class":100}," process_into",[71,696,610],{"class":77},[71,698,138],{"class":84},[71,700,615],{"class":84},[71,702,618],{"class":77},[71,704,621],{"class":100},[71,706,707],{"class":77},"], out",[71,709,138],{"class":84},[71,711,141],{"class":84},[71,713,714],{"class":77}," [",[71,716,621],{"class":100},[71,718,719],{"class":77},"]) {\n",[71,721,722,725,728,731,734,736,738,740,742,745,748,750,752,754,756],{"class":73,"line":126},[71,723,724],{"class":84},"    for",[71,726,727],{"class":77}," (i, x) ",[71,729,730],{"class":84},"in",[71,732,733],{"class":77}," items",[71,735,156],{"class":84},[71,737,159],{"class":100},[71,739,645],{"class":77},[71,741,156],{"class":84},[71,743,744],{"class":100},"enumerate",[71,746,747],{"class":77},"() { out[i] ",[71,749,375],{"class":84},[71,751,662],{"class":77},[71,753,184],{"class":84},[71,755,667],{"class":177},[71,757,758],{"class":77},"; }\n",[71,760,761],{"class":73,"line":150},[71,762,203],{"class":77},[14,764,765,282,768,771],{},[54,766,767],{},"String::with_capacity",[54,769,770],{},"Vec::with_capacity"," to avoid regrowth.",[50,773,775,776,779,780,783],{"id":774},"_2-use-t-str-in-apis","2. Use ",[54,777,778],{},"&[T]"," \u002F ",[54,781,782],{},"&str"," in APIs",[14,785,786,787,790,791,794],{},"Don't take ",[54,788,789],{},"&Vec\u003CT>"," or ",[54,792,793],{},"&String"," — they impose ownership and lose the more general slice form. Slices are flexible and equally fast.",[50,796,798],{"id":797},"_3-choose-iterators-over-explicit-loops-sometimes","3. Choose Iterators Over Explicit Loops (Sometimes)",[14,800,801],{},"Iterators often compile to tighter loops because the compiler can reason about them. But for very tight inner loops, the explicit form sometimes wins (or with manual SIMD). Profile both.",[50,803,805],{"id":804},"_4-box-large-struct-fields","4. Box Large Struct Fields",[14,807,808,809,812,813,816,817,820,821,824],{},"A struct with a large ",[54,810,811],{},"Vec"," field still has its ",[54,814,815],{},"(ptr, len, cap)"," header inline (24 bytes), but a large ",[54,818,819],{},"[u8; 1024]"," field makes the struct huge. Use ",[54,822,823],{},"Box\u003C[u8; 1024]>"," for large fixed-size data to keep the struct small (good for cache and copying).",[50,826,828,829,832],{"id":827},"_5-avoid-boxdyn-trait-in-hot-paths","5. Avoid ",[54,830,831],{},"Box\u003Cdyn Trait>"," in Hot Paths",[14,834,835],{},"Vtable indirection is ~few ns but kills inlining. Genericize hot paths.",[50,837,839],{"id":838},"_6-cache-locality","6. Cache Locality",[841,842,843,853,863],"ul",{},[26,844,845,846,849,850,156],{},"Flat ",[54,847,848],{},"Vec\u003CT>"," over ",[54,851,852],{},"Vec\u003CVec\u003CT>>",[26,854,855,858,859,862],{},[54,856,857],{},"ArrayVec","\u002F",[54,860,861],{},"SmallVec"," for inline storage.",[26,864,865],{},"Structure-of-arrays over array-of-structures for SIMD-friendly access.",[50,867,869,870,873,874,858,877,880],{"id":868},"_7-simd-via-stdsimd-nightly-or-widepulp-stable","7. SIMD via ",[54,871,872],{},"std::simd"," (nightly) or ",[54,875,876],{},"wide",[54,878,879],{},"pulp"," (stable)",[59,882,883],{"language":61},[63,884,886],{"className":65,"code":885,"language":61,"meta":67,"style":67},"#![feature(portable_simd)]\nuse std::simd::f32x4;\nlet a = f32x4::from_array([1.0, 2.0, 3.0, 4.0]);\nlet b = f32x4::from_array([5.0, 6.0, 7.0, 8.0]);\nlet c = a + b;\n",[54,887,888,893,909,950,987],{"__ignoreMap":67},[71,889,890],{"class":73,"line":74},[71,891,892],{"class":77},"#![feature(portable_simd)]\n",[71,894,895,897,899,901,904,906],{"class":73,"line":81},[71,896,97],{"class":84},[71,898,378],{"class":100},[71,900,104],{"class":84},[71,902,903],{"class":100},"simd",[71,905,104],{"class":84},[71,907,908],{"class":77},"f32x4;\n",[71,910,911,913,916,918,921,923,926,929,932,934,937,939,942,944,947],{"class":73,"line":94},[71,912,369],{"class":84},[71,914,915],{"class":77}," a ",[71,917,375],{"class":84},[71,919,920],{"class":100}," f32x4",[71,922,104],{"class":84},[71,924,925],{"class":100},"from_array",[71,927,928],{"class":77},"([",[71,930,931],{"class":177},"1.0",[71,933,282],{"class":77},[71,935,936],{"class":177},"2.0",[71,938,282],{"class":77},[71,940,941],{"class":177},"3.0",[71,943,282],{"class":77},[71,945,946],{"class":177},"4.0",[71,948,949],{"class":77},"]);\n",[71,951,952,954,957,959,961,963,965,967,970,972,975,977,980,982,985],{"class":73,"line":113},[71,953,369],{"class":84},[71,955,956],{"class":77}," b ",[71,958,375],{"class":84},[71,960,920],{"class":100},[71,962,104],{"class":84},[71,964,925],{"class":100},[71,966,928],{"class":77},[71,968,969],{"class":177},"5.0",[71,971,282],{"class":77},[71,973,974],{"class":177},"6.0",[71,976,282],{"class":77},[71,978,979],{"class":177},"7.0",[71,981,282],{"class":77},[71,983,984],{"class":177},"8.0",[71,986,949],{"class":77},[71,988,989,991,994,996,998,1000],{"class":73,"line":120},[71,990,369],{"class":84},[71,992,993],{"class":77}," c ",[71,995,375],{"class":84},[71,997,915],{"class":77},[71,999,184],{"class":84},[71,1001,1002],{"class":77}," b;\n",[14,1004,1005,1006,1009],{},"For auto-vectorization, write iterator chains and let LLVM do it; check with ",[54,1007,1008],{},"cargo asm"," or Godbolt.",[50,1011,1013,1014,1017],{"id":1012},"_8-inline-selectively","8. ",[54,1015,1016],{},"#[inline]"," Selectively",[59,1019,1020],{"language":61},[63,1021,1023],{"className":65,"code":1022,"language":61,"meta":67,"style":67},"#[inline]\nfn small() -> u32 { \u002F* ... *\u002F }\n\n#[inline(always)]\nfn tiny() -> u32 { \u002F* ... *\u002F }\n",[54,1024,1025,1030,1054,1058,1063],{"__ignoreMap":67},[71,1026,1027],{"class":73,"line":74},[71,1028,1029],{"class":77},"#[inline]\n",[71,1031,1032,1034,1037,1040,1042,1045,1048,1051],{"class":73,"line":81},[71,1033,129],{"class":84},[71,1035,1036],{"class":100}," small",[71,1038,1039],{"class":77},"() ",[71,1041,627],{"class":84},[71,1043,1044],{"class":100}," u32",[71,1046,1047],{"class":77}," { ",[71,1049,1050],{"class":599},"\u002F* ... *\u002F",[71,1052,1053],{"class":77}," }\n",[71,1055,1056],{"class":73,"line":94},[71,1057,117],{"emptyLinePlaceholder":116},[71,1059,1060],{"class":73,"line":113},[71,1061,1062],{"class":77},"#[inline(always)]\n",[71,1064,1065,1067,1070,1072,1074,1076,1078,1080],{"class":73,"line":120},[71,1066,129],{"class":84},[71,1068,1069],{"class":100}," tiny",[71,1071,1039],{"class":77},[71,1073,627],{"class":84},[71,1075,1044],{"class":100},[71,1077,1047],{"class":77},[71,1079,1050],{"class":599},[71,1081,1053],{"class":77},[14,1083,1084,1085,1088],{},"Don't ",[54,1086,1087],{},"#[inline(always)]"," everywhere — it bloats code and hurts i-cache.",[50,1090,1092],{"id":1091},"_9-avoid-heap-allocations-in-hot-loops","9. Avoid Heap Allocations in Hot Loops",[841,1094,1095,1101,1108],{},[26,1096,1097,1098,156],{},"Reuse buffers via ",[54,1099,1100],{},"&mut Vec",[26,1102,1103,1104,1107],{},"Use ",[54,1105,1106],{},"arrayvec::ArrayVec"," for fixed-size buffers.",[26,1109,1103,1110,1113],{},[54,1111,1112],{},"smallvec::SmallVec"," for small-but-may-grow.",[50,1115,1117,1118,1121],{"id":1116},"_10-use-mut-t-for-in-place-mutation","10. Use ",[54,1119,1120],{},"&mut [T]"," for In-Place Mutation",[59,1123,1124],{"language":61},[63,1125,1127],{"className":65,"code":1126,"language":61,"meta":67,"style":67},"fn sum_of_squares(v: &mut [i32]) {\n    for x in v.iter_mut() { *x = *x * *x; }\n}\n",[54,1128,1129,1150,1189],{"__ignoreMap":67},[71,1130,1131,1133,1136,1139,1141,1143,1145,1148],{"class":73,"line":74},[71,1132,129],{"class":84},[71,1134,1135],{"class":100}," sum_of_squares",[71,1137,1138],{"class":77},"(v",[71,1140,138],{"class":84},[71,1142,141],{"class":84},[71,1144,714],{"class":77},[71,1146,1147],{"class":100},"i32",[71,1149,719],{"class":77},[71,1151,1152,1154,1156,1158,1161,1163,1166,1169,1172,1175,1177,1180,1182,1184,1186],{"class":73,"line":81},[71,1153,724],{"class":84},[71,1155,662],{"class":77},[71,1157,730],{"class":84},[71,1159,1160],{"class":77}," v",[71,1162,156],{"class":84},[71,1164,1165],{"class":100},"iter_mut",[71,1167,1168],{"class":77},"() { ",[71,1170,1171],{"class":84},"*",[71,1173,1174],{"class":77},"x ",[71,1176,375],{"class":84},[71,1178,1179],{"class":84}," *",[71,1181,1174],{"class":77},[71,1183,1171],{"class":84},[71,1185,1179],{"class":84},[71,1187,1188],{"class":77},"x; }\n",[71,1190,1191],{"class":73,"line":94},[71,1192,203],{"class":77},[14,1194,1195],{},"Avoids allocation; cache-friendly.",[50,1197,1199],{"id":1198},"_11-lock-granularity","11. Lock Granularity",[841,1201,1202,1208,1211],{},[26,1203,1204,1207],{},[54,1205,1206],{},"RwLock"," for read-heavy.",[26,1209,1210],{},"Shard locks across N buckets for parallel writes.",[26,1212,1213],{},"Lock-free via atomics when possible.",[50,1215,1217],{"id":1216},"_12-avoid-reallocations","12. Avoid Reallocations",[59,1219,1220],{"language":61},[63,1221,1223],{"className":65,"code":1222,"language":61,"meta":67,"style":67},"let mut v = Vec::with_capacity(N);\nfor x in iter { v.push(x); }\n",[54,1224,1225,1252],{"__ignoreMap":67},[71,1226,1227,1229,1232,1235,1237,1239,1241,1244,1246,1249],{"class":73,"line":74},[71,1228,369],{"class":84},[71,1230,1231],{"class":84}," mut",[71,1233,1234],{"class":77}," v ",[71,1236,375],{"class":84},[71,1238,630],{"class":100},[71,1240,104],{"class":84},[71,1242,1243],{"class":100},"with_capacity",[71,1245,162],{"class":77},[71,1247,1248],{"class":100},"N",[71,1250,1251],{"class":77},");\n",[71,1253,1254,1257,1259,1261,1264,1266,1269],{"class":73,"line":81},[71,1255,1256],{"class":84},"for",[71,1258,662],{"class":77},[71,1260,730],{"class":84},[71,1262,1263],{"class":77}," iter { v",[71,1265,156],{"class":84},[71,1267,1268],{"class":100},"push",[71,1270,1271],{"class":77},"(x); }\n",[50,1273,1275,1276,1279],{"id":1274},"_13-use-arcclone-carefully","13. Use ",[54,1277,1278],{},"Arc::clone"," Carefully",[14,1281,1282,1283,1285],{},"Each ",[54,1284,1278],{}," does an atomic increment — much cheaper than a deep clone but not free. Avoid in tightest loops.",[50,1287,1289,1290,1293,1294],{"id":1288},"_14-memreplace-and-memtake","14. ",[54,1291,1292],{},"mem::replace"," and ",[54,1295,1296],{},"mem::take",[59,1298,1299],{"language":61},[63,1300,1302],{"className":65,"code":1301,"language":61,"meta":67,"style":67},"let old = mem::take(&mut self.buffer);   \u002F\u002F self.buffer is now empty\nprocess(old);\n",[54,1303,1304,1337],{"__ignoreMap":67},[71,1305,1306,1308,1311,1313,1316,1318,1321,1323,1326,1329,1331,1334],{"class":73,"line":74},[71,1307,369],{"class":84},[71,1309,1310],{"class":77}," old ",[71,1312,375],{"class":84},[71,1314,1315],{"class":100}," mem",[71,1317,104],{"class":84},[71,1319,1320],{"class":100},"take",[71,1322,162],{"class":77},[71,1324,1325],{"class":84},"&mut",[71,1327,1328],{"class":177}," self",[71,1330,156],{"class":84},[71,1332,1333],{"class":77},"buffer);   ",[71,1335,1336],{"class":599},"\u002F\u002F self.buffer is now empty\n",[71,1338,1339,1342],{"class":73,"line":81},[71,1340,1341],{"class":100},"process",[71,1343,1344],{"class":77},"(old);\n",[14,1346,1347],{},"Avoids cloning; useful for swap-and-go state.",[50,1349,1351],{"id":1350},"_15-reduce-trait-object-dispatch","15. Reduce Trait Object Dispatch",[59,1353,1354],{"language":61},[63,1355,1357],{"className":65,"code":1356,"language":61,"meta":67,"style":67},"\u002F\u002F Generic\nfn sum\u003CT>(v: &[T]) -> T where T: Sum + Copy { v.iter().copied().sum() }\n\n\u002F\u002F Box\u003Cdyn> — slower\nfn sum_dyn(v: &[Box\u003Cdyn Additive>]) { \u002F* vtable per call *\u002F }\n",[54,1358,1359,1364,1433,1437,1442],{"__ignoreMap":67},[71,1360,1361],{"class":73,"line":74},[71,1362,1363],{"class":599},"\u002F\u002F Generic\n",[71,1365,1366,1368,1371,1373,1376,1379,1381,1383,1385,1387,1389,1391,1394,1397,1399,1401,1404,1407,1410,1413,1415,1417,1419,1421,1424,1426,1428,1431],{"class":73,"line":81},[71,1367,129],{"class":84},[71,1369,1370],{"class":100}," sum",[71,1372,633],{"class":77},[71,1374,1375],{"class":100},"T",[71,1377,1378],{"class":77},">(v",[71,1380,138],{"class":84},[71,1382,615],{"class":84},[71,1384,618],{"class":77},[71,1386,1375],{"class":100},[71,1388,624],{"class":77},[71,1390,627],{"class":84},[71,1392,1393],{"class":100}," T",[71,1395,1396],{"class":84}," where",[71,1398,1393],{"class":100},[71,1400,138],{"class":84},[71,1402,1403],{"class":100}," Sum",[71,1405,1406],{"class":84}," +",[71,1408,1409],{"class":100}," Copy",[71,1411,1412],{"class":77}," { v",[71,1414,156],{"class":84},[71,1416,159],{"class":100},[71,1418,645],{"class":77},[71,1420,156],{"class":84},[71,1422,1423],{"class":100},"copied",[71,1425,645],{"class":77},[71,1427,156],{"class":84},[71,1429,1430],{"class":100},"sum",[71,1432,678],{"class":77},[71,1434,1435],{"class":73,"line":94},[71,1436,117],{"emptyLinePlaceholder":116},[71,1438,1439],{"class":73,"line":113},[71,1440,1441],{"class":599},"\u002F\u002F Box\u003Cdyn> — slower\n",[71,1443,1444,1446,1449,1451,1453,1455,1457,1460,1462,1465,1468,1471,1474],{"class":73,"line":120},[71,1445,129],{"class":84},[71,1447,1448],{"class":100}," sum_dyn",[71,1450,1138],{"class":77},[71,1452,138],{"class":84},[71,1454,615],{"class":84},[71,1456,618],{"class":77},[71,1458,1459],{"class":100},"Box",[71,1461,633],{"class":77},[71,1463,1464],{"class":84},"dyn",[71,1466,1467],{"class":100}," Additive",[71,1469,1470],{"class":77},">]) { ",[71,1472,1473],{"class":599},"\u002F* vtable per call *\u002F",[71,1475,1053],{"class":77},[50,1477,1479,1480,1483],{"id":1478},"_16-cow-to-avoid-allocations","16. ",[54,1481,1482],{},"Cow"," to Avoid Allocations",[59,1485,1486],{"language":61},[63,1487,1489],{"className":65,"code":1488,"language":61,"meta":67,"style":67},"fn normalize(s: &str) -> Cow\u003Cstr> {\n    if needs_transform(s) { Cow::Owned(s.to_uppercase()) } else { Cow::Borrowed(s) }\n}\n",[54,1490,1491,1522,1565],{"__ignoreMap":67},[71,1492,1493,1495,1498,1501,1503,1505,1508,1510,1512,1515,1517,1519],{"class":73,"line":74},[71,1494,129],{"class":84},[71,1496,1497],{"class":100}," normalize",[71,1499,1500],{"class":77},"(s",[71,1502,138],{"class":84},[71,1504,615],{"class":84},[71,1506,1507],{"class":100},"str",[71,1509,181],{"class":77},[71,1511,627],{"class":84},[71,1513,1514],{"class":100}," Cow",[71,1516,633],{"class":77},[71,1518,1507],{"class":100},[71,1520,1521],{"class":77},"> {\n",[71,1523,1524,1527,1530,1533,1535,1537,1540,1542,1544,1547,1550,1553,1555,1557,1559,1562],{"class":73,"line":81},[71,1525,1526],{"class":84},"    if",[71,1528,1529],{"class":100}," needs_transform",[71,1531,1532],{"class":77},"(s) { ",[71,1534,1482],{"class":100},[71,1536,104],{"class":84},[71,1538,1539],{"class":100},"Owned",[71,1541,1500],{"class":77},[71,1543,156],{"class":84},[71,1545,1546],{"class":100},"to_uppercase",[71,1548,1549],{"class":77},"()) } ",[71,1551,1552],{"class":84},"else",[71,1554,1047],{"class":77},[71,1556,1482],{"class":100},[71,1558,104],{"class":84},[71,1560,1561],{"class":100},"Borrowed",[71,1563,1564],{"class":77},"(s) }\n",[71,1566,1567],{"class":73,"line":94},[71,1568,203],{"class":77},[50,1570,1572],{"id":1571},"_17-pre-compute-and-cache","17. Pre-compute and Cache",[59,1574,1575],{"language":61},[63,1576,1578],{"className":65,"code":1577,"language":61,"meta":67,"style":67},"struct Cached { data: Vec\u003Cu8> }\nimpl Cached {\n    fn lookup(&self, key: usize) -> u8 { self.data[key] }\n}\n",[54,1579,1580,1602,1612,1652],{"__ignoreMap":67},[71,1581,1582,1585,1588,1591,1593,1595,1597,1599],{"class":73,"line":74},[71,1583,1584],{"class":84},"struct",[71,1586,1587],{"class":100}," Cached",[71,1589,1590],{"class":77}," { data",[71,1592,138],{"class":84},[71,1594,630],{"class":100},[71,1596,633],{"class":77},[71,1598,621],{"class":100},[71,1600,1601],{"class":77},"> }\n",[71,1603,1604,1607,1609],{"class":73,"line":81},[71,1605,1606],{"class":84},"impl",[71,1608,1587],{"class":100},[71,1610,1611],{"class":77}," {\n",[71,1613,1614,1617,1620,1622,1625,1628,1631,1633,1636,1638,1640,1643,1645,1647,1649],{"class":73,"line":94},[71,1615,1616],{"class":84},"    fn",[71,1618,1619],{"class":100}," lookup",[71,1621,162],{"class":77},[71,1623,1624],{"class":84},"&",[71,1626,1627],{"class":177},"self",[71,1629,1630],{"class":77},", key",[71,1632,138],{"class":84},[71,1634,1635],{"class":100}," usize",[71,1637,181],{"class":77},[71,1639,627],{"class":84},[71,1641,1642],{"class":100}," u8",[71,1644,1047],{"class":77},[71,1646,1627],{"class":177},[71,1648,156],{"class":84},[71,1650,1651],{"class":77},"data[key] }\n",[71,1653,1654],{"class":73,"line":113},[71,1655,203],{"class":77},[14,1657,1658],{},"Avoid recomputing in hot paths.",[50,1660,1662],{"id":1661},"_18-string-interning","18. String Interning",[14,1664,1665,1666,858,1669,1672],{},"For repeated short strings, use ",[54,1667,1668],{},"string_interner",[54,1670,1671],{},"lasso"," to assign integer IDs.",[50,1674,1676,1677,1680],{"id":1675},"_19-use-static-where-appropriate","19. Use ",[54,1678,1679],{},"&'static"," Where Appropriate",[14,1682,1683],{},"Avoids lifetime-tracking overhead in some generic contexts. Don't overuse.",[50,1685,1687],{"id":1686},"_20-compile-time-computation","20. Compile-Time Computation",[59,1689,1690],{"language":61},[63,1691,1693],{"className":65,"code":1692,"language":61,"meta":67,"style":67},"const N: usize = 1000;\nlet arr = [0; N];\n",[54,1694,1695,1715],{"__ignoreMap":67},[71,1696,1697,1700,1703,1705,1707,1710,1713],{"class":73,"line":74},[71,1698,1699],{"class":84},"const",[71,1701,1702],{"class":177}," N",[71,1704,138],{"class":84},[71,1706,1635],{"class":100},[71,1708,1709],{"class":84}," =",[71,1711,1712],{"class":177}," 1000",[71,1714,110],{"class":77},[71,1716,1717,1719,1722,1724,1726,1729,1732,1734],{"class":73,"line":81},[71,1718,369],{"class":84},[71,1720,1721],{"class":77}," arr ",[71,1723,375],{"class":84},[71,1725,714],{"class":77},[71,1727,1728],{"class":177},"0",[71,1730,1731],{"class":77},"; ",[71,1733,1248],{"class":100},[71,1735,1736],{"class":77},"];\n",[14,1738,1739,1740,858,1742,1745],{},"Move computation to compile time via ",[54,1741,1699],{},[54,1743,1744],{},"const fn"," when possible.",[18,1747,1749,1752],{"id":1748},"release-profile-pitfalls",[54,1750,1751],{},"release"," Profile Pitfalls",[841,1754,1755,1774,1782,1790],{},[26,1756,1757,1762,1763,1766,1767,282,1770,1773],{},[29,1758,1759,1760],{},"Default ",[54,1761,1751],{},": ",[54,1764,1765],{},"opt-level = 3"," but ",[54,1768,1769],{},"lto = false",[54,1771,1772],{},"codegen-units = 16"," (parallel compile, less optimization). For final binaries, bump these.",[26,1775,1776,1781],{},[29,1777,1778],{},[54,1779,1780],{},"panic = \"abort\""," can unlock more optimizations (no unwinding tables).",[26,1783,1784,1789],{},[29,1785,1786],{},[54,1787,1788],{},"strip = \"symbols\""," reduces binary size.",[26,1791,1792,1797],{},[29,1793,1794],{},[54,1795,1796],{},"opt-level = \"z\""," minimizes size, often at a perf cost.",[18,1799,1801],{"id":1800},"measuring-allocations","Measuring Allocations",[14,1803,1804],{},"Use a custom allocator that logs:",[59,1806,1807],{"language":61},[63,1808,1810],{"className":65,"code":1809,"language":61,"meta":67,"style":67},"use std::alloc::{GlobalAlloc, Layout, System};\n\nstruct Counting;\nunsafe impl GlobalAlloc for Counting {\n    unsafe fn alloc(&self, l: Layout) -> *mut u8 { eprintln!(\"alloc {:?}\", l); System.alloc(l) }\n    unsafe fn dealloc(&self, p: *mut u8, l: Layout) { System.dealloc(p, l) }\n}\n\n#[global_allocator]\nstatic A: Counting = Counting;\n",[54,1811,1812,1843,1847,1856,1874,1930,1973,1977,1981,1987],{"__ignoreMap":67},[71,1813,1814,1816,1818,1820,1823,1825,1828,1831,1833,1836,1838,1841],{"class":73,"line":74},[71,1815,97],{"class":84},[71,1817,378],{"class":100},[71,1819,104],{"class":84},[71,1821,1822],{"class":100},"alloc",[71,1824,104],{"class":84},[71,1826,1827],{"class":77},"{",[71,1829,1830],{"class":100},"GlobalAlloc",[71,1832,282],{"class":77},[71,1834,1835],{"class":100},"Layout",[71,1837,282],{"class":77},[71,1839,1840],{"class":100},"System",[71,1842,240],{"class":77},[71,1844,1845],{"class":73,"line":81},[71,1846,117],{"emptyLinePlaceholder":116},[71,1848,1849,1851,1854],{"class":73,"line":94},[71,1850,1584],{"class":84},[71,1852,1853],{"class":100}," Counting",[71,1855,110],{"class":77},[71,1857,1858,1861,1864,1867,1870,1872],{"class":73,"line":113},[71,1859,1860],{"class":84},"unsafe",[71,1862,1863],{"class":84}," impl",[71,1865,1866],{"class":100}," GlobalAlloc",[71,1868,1869],{"class":84}," for",[71,1871,1853],{"class":100},[71,1873,1611],{"class":77},[71,1875,1876,1879,1882,1885,1887,1889,1891,1894,1896,1899,1901,1903,1906,1908,1910,1913,1915,1918,1921,1923,1925,1927],{"class":73,"line":120},[71,1877,1878],{"class":84},"    unsafe",[71,1880,1881],{"class":84}," fn",[71,1883,1884],{"class":100}," alloc",[71,1886,162],{"class":77},[71,1888,1624],{"class":84},[71,1890,1627],{"class":177},[71,1892,1893],{"class":77},", l",[71,1895,138],{"class":84},[71,1897,1898],{"class":100}," Layout",[71,1900,181],{"class":77},[71,1902,627],{"class":84},[71,1904,1905],{"class":84}," *mut",[71,1907,1642],{"class":100},[71,1909,1047],{"class":77},[71,1911,1912],{"class":100},"eprintln!",[71,1914,162],{"class":77},[71,1916,1917],{"class":278},"\"alloc {:?}\"",[71,1919,1920],{"class":77},", l); ",[71,1922,1840],{"class":100},[71,1924,156],{"class":84},[71,1926,1822],{"class":100},[71,1928,1929],{"class":77},"(l) }\n",[71,1931,1932,1934,1936,1939,1941,1943,1945,1948,1950,1952,1954,1956,1958,1960,1963,1965,1967,1970],{"class":73,"line":126},[71,1933,1878],{"class":84},[71,1935,1881],{"class":84},[71,1937,1938],{"class":100}," dealloc",[71,1940,162],{"class":77},[71,1942,1624],{"class":84},[71,1944,1627],{"class":177},[71,1946,1947],{"class":77},", p",[71,1949,138],{"class":84},[71,1951,1905],{"class":84},[71,1953,1642],{"class":100},[71,1955,1893],{"class":77},[71,1957,138],{"class":84},[71,1959,1898],{"class":100},[71,1961,1962],{"class":77},") { ",[71,1964,1840],{"class":100},[71,1966,156],{"class":84},[71,1968,1969],{"class":100},"dealloc",[71,1971,1972],{"class":77},"(p, l) }\n",[71,1974,1975],{"class":73,"line":150},[71,1976,203],{"class":77},[71,1978,1979],{"class":73,"line":200},[71,1980,117],{"emptyLinePlaceholder":116},[71,1982,1984],{"class":73,"line":1983},9,[71,1985,1986],{"class":77},"#[global_allocator]\n",[71,1988,1990,1993,1996,1998,2000,2002,2004],{"class":73,"line":1989},10,[71,1991,1992],{"class":84},"static",[71,1994,1995],{"class":100}," A",[71,1997,138],{"class":84},[71,1999,1853],{"class":100},[71,2001,1709],{"class":84},[71,2003,1853],{"class":100},[71,2005,110],{"class":77},[14,2007,2008,2009,2012],{},"Or use ",[54,2010,2011],{},"dhat"," for heap profiling.",[18,2014,2016],{"id":2015},"cargo-bloat",[54,2017,2018],{},"cargo bloat",[59,2020,2021],{"language":436},[63,2022,2024],{"className":439,"code":2023,"language":436,"meta":67,"style":67},"cargo install cargo-bloat\ncargo bloat --release\ncargo bloat --release --crates\n",[54,2025,2026,2035,2044],{"__ignoreMap":67},[71,2027,2028,2030,2032],{"class":73,"line":74},[71,2029,447],{"class":100},[71,2031,490],{"class":278},[71,2033,2034],{"class":278}," cargo-bloat\n",[71,2036,2037,2039,2042],{"class":73,"line":81},[71,2038,447],{"class":100},[71,2040,2041],{"class":278}," bloat",[71,2043,453],{"class":177},[71,2045,2046,2048,2050,2053],{"class":73,"line":94},[71,2047,447],{"class":100},[71,2049,2041],{"class":278},[71,2051,2052],{"class":177}," --release",[71,2054,2055],{"class":177}," --crates\n",[14,2057,2058],{},"Shows which functions take the most binary size.",[18,2060,2062],{"id":2061},"inspecting-assembly","Inspecting Assembly",[59,2064,2065],{"language":436},[63,2066,2068],{"className":439,"code":2067,"language":436,"meta":67,"style":67},"cargo install cargo-asm\ncargo asm my_crate::function\n",[54,2069,2070,2079],{"__ignoreMap":67},[71,2071,2072,2074,2076],{"class":73,"line":74},[71,2073,447],{"class":100},[71,2075,490],{"class":278},[71,2077,2078],{"class":278}," cargo-asm\n",[71,2080,2081,2083,2086],{"class":73,"line":81},[71,2082,447],{"class":100},[71,2084,2085],{"class":278}," asm",[71,2087,2088],{"class":278}," my_crate::function\n",[14,2090,2091],{},"Or use Godbolt (godbolt.org) — paste Rust code, see assembly.",[18,2093,2095],{"id":2094},"common-performance-pitfalls","Common Performance Pitfalls",[841,2097,2098,2112,2125,2140,2155,2166,2180,2188,2199,2208,2216,2225,2243,2256],{},[26,2099,2100,2109,2110,156],{},[29,2101,2102,2105,2106],{},[54,2103,2104],{},"String::new()"," followed by many ",[54,2107,2108],{},"push_str",": use ",[54,2111,1243],{},[26,2113,2114,2120,2121,2124],{},[29,2115,2116,2119],{},[54,2117,2118],{},"format!"," in hot loops",": pre-format or use ",[54,2122,2123],{},"write!"," into a reused buffer.",[26,2126,2127,1762,2133,858,2136,2139],{},[29,2128,2129,2132],{},[54,2130,2131],{},"Vec\u003Cu8>"," for byte parsing",[54,2134,2135],{},"bytes::Bytes",[54,2137,2138],{},"BytesMut"," are often faster.",[26,2141,2142,2109,2148,858,2151,2154],{},[29,2143,2144,2147],{},[54,2145,2146],{},"HashMap"," with crypto-strong hash",[54,2149,2150],{},"FxHashMap",[54,2152,2153],{},"AHashMap"," for non-adversarial keys.",[26,2156,2157,1762,2163,2165],{},[29,2158,2159,2162],{},[54,2160,2161],{},"Vec::push"," in a counted loop",[54,2164,770],{}," once.",[26,2167,2168,2177,2178,156],{},[29,2169,2170,2173,2174,2176],{},[54,2171,2172],{},"to_string()"," on a ",[54,2175,782],{}," you only need to read",": just use the ",[54,2179,782],{},[26,2181,2182,2187],{},[29,2183,2184,2186],{},[54,2185,1278],{}," in inner loop",": clone once, reuse.",[26,2189,2190,2109,2195,2198],{},[29,2191,2192,2194],{},[54,2193,2146],{}," lookup-then-insert",[54,2196,2197],{},"entry"," (one hash).",[26,2200,2201,2207],{},[29,2202,2203,2204],{},"Locks held across ",[54,2205,2206],{},"await",": contention; drop lock first.",[26,2209,2210,2215],{},[29,2211,2212,2214],{},[54,2213,852],{}," matrices",": flat layout + index math is faster.",[26,2217,2218,2224],{},[29,2219,2220,2223],{},[54,2221,2222],{},"Box\u003Cdyn>"," in inner loops",": indirect calls prevent inlining.",[26,2226,2227,1762,2236,2238,2239,2242],{},[29,2228,2229,2232,2233],{},[54,2230,2231],{},"cloned()"," instead of ",[54,2234,2235],{},"copied()",[54,2237,1423],{}," is faster for ",[54,2240,2241],{},"Copy"," types.",[26,2244,2245,2109,2253,2255],{},[29,2246,2247,2249,2250],{},[54,2248,2131],{}," from ",[54,2251,2252],{},"read_to_end",[54,2254,770],{}," if size is known.",[26,2257,2258,1762,2267,2270],{},[29,2259,2260,2263,2264],{},[54,2261,2262],{},"String::from_utf8"," then ",[54,2265,2266],{},"unwrap",[54,2268,2269],{},"from_utf8_lossy"," avoids the check.",[18,2272,2274],{"id":2273},"memory-layout","Memory Layout",[841,2276,2277,2283,2289,2295],{},[26,2278,2279,2282],{},[54,2280,2281],{},"#[repr(C)]",": fixed, predictable, no padding-optimization.",[26,2284,2285,2288],{},[54,2286,2287],{},"#[repr(transparent)]",": same layout as inner.",[26,2290,2291,2294],{},[54,2292,2293],{},"#[repr(packed)]",": no padding, alignment 1 — slow on many platforms, UB risk.",[26,2296,2297],{},"Field reordering (default Rust layout) minimizes padding; let the compiler do it.",[18,2299,2301,1898],{"id":2300},"stdalloc-layout",[54,2302,2303],{},"std::alloc",[14,2305,2306,2307,2310,2311,858,2314,2316],{},"Allocations must be aligned to ",[54,2308,2309],{},"Layout::align",". Mismatched alignment is UB. ",[54,2312,2313],{},"Box::new_uninit_slice",[54,2315,770],{}," handle this for you.",[18,2318,2320],{"id":2319},"async-performance","Async Performance",[841,2322,2323,2330,2343,2346],{},[26,2324,2325,2326,2329],{},"Avoid ",[54,2327,2328],{},"Box\u003Cdyn Future>"," in hot paths; use generics.",[26,2331,2325,2332,2335,2336,858,2339,2342],{},[54,2333,2334],{},"tokio::spawn"," for short-lived work — overhead. Use ",[54,2337,2338],{},"join!",[54,2340,2341],{},"FuturesUnordered"," instead.",[26,2344,2345],{},"Bounded channels for backpressure (vs unbounded that grow).",[26,2347,2348,2351],{},[54,2349,2350],{},"current_thread"," runtime for single-threaded apps.",[18,2353,2355],{"id":2354},"summary","Summary",[14,2357,2358,2359,282,2361,282,2364,282,2366,2368,2369,282,2371,2373,2374,2376,2377,2380,2381,2384],{},"Profile with ",[54,2360,214],{},[54,2362,2363],{},"flamegraph",[54,2365,502],{},[54,2367,2018],{},". Optimize hot paths: avoid allocation, use slices, generic over ",[54,2370,1464],{},[54,2372,1243],{},", lock granularity, SIMD. Use ",[54,2375,1751],{}," profile + ",[54,2378,2379],{},"lto = \"fat\""," + ",[54,2382,2383],{},"codegen-units = 1"," for final binaries. Don't trust intuition; measure. Iterate.",[14,2386,2387],{},"Next: Documentation.",[2389,2390,2391],"style",{},"html pre.shiki code .ssxIu, html code.shiki .ssxIu{--shiki-default:#24292E;--shiki-github-dark:#E1E4E8}html pre.shiki code .svdQ7, html code.shiki .svdQ7{--shiki-default:#D73A49;--shiki-github-dark:#F97583}html pre.shiki code .sIsaT, html code.shiki .sIsaT{--shiki-default:#6F42C1;--shiki-github-dark:#B392F0}html pre.shiki code .snvgF, html code.shiki .snvgF{--shiki-default:#005CC5;--shiki-github-dark:#79B8FF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .github-dark .shiki span {color: var(--shiki-github-dark);background: var(--shiki-github-dark-bg);font-style: var(--shiki-github-dark-font-style);font-weight: var(--shiki-github-dark-font-weight);text-decoration: var(--shiki-github-dark-text-decoration);}html.github-dark .shiki span {color: var(--shiki-github-dark);background: var(--shiki-github-dark-bg);font-style: var(--shiki-github-dark-font-style);font-weight: var(--shiki-github-dark-font-weight);text-decoration: var(--shiki-github-dark-text-decoration);}html pre.shiki code .sJ6F3, html code.shiki .sJ6F3{--shiki-default:#032F62;--shiki-github-dark:#9ECBFF}html pre.shiki code .sdCPZ, html code.shiki .sdCPZ{--shiki-default:#6A737D;--shiki-github-dark:#6A737D}",{"title":67,"searchDepth":81,"depth":81,"links":2393},[2394,2395,2402,2411,2442,2444,2445,2446,2447,2448,2449,2451,2452],{"id":20,"depth":81,"text":21},{"id":47,"depth":81,"text":48,"children":2396},[2397,2399,2401],{"id":52,"depth":94,"text":2398},"cargo bench (nightly)",{"id":211,"depth":94,"text":2400},"criterion (stable, recommended)",{"id":353,"depth":94,"text":354},{"id":425,"depth":81,"text":426,"children":2403},[2404,2406,2407,2409],{"id":429,"depth":94,"text":2405},"perf (Linux)",{"id":502,"depth":94,"text":502},{"id":534,"depth":94,"text":2408},"Instruments (macOS)",{"id":569,"depth":94,"text":2410},"dtrace, vtune (advanced)",{"id":582,"depth":81,"text":583,"children":2412},[2413,2414,2416,2417,2418,2420,2421,2423,2425,2426,2428,2429,2430,2432,2434,2435,2437,2438,2439,2441],{"id":586,"depth":94,"text":587},{"id":774,"depth":94,"text":2415},"2. Use &[T] \u002F &str in APIs",{"id":797,"depth":94,"text":798},{"id":804,"depth":94,"text":805},{"id":827,"depth":94,"text":2419},"5. Avoid Box\u003Cdyn Trait> in Hot Paths",{"id":838,"depth":94,"text":839},{"id":868,"depth":94,"text":2422},"7. SIMD via std::simd (nightly) or wide\u002Fpulp (stable)",{"id":1012,"depth":94,"text":2424},"8. #[inline] Selectively",{"id":1091,"depth":94,"text":1092},{"id":1116,"depth":94,"text":2427},"10. Use &mut [T] for In-Place Mutation",{"id":1198,"depth":94,"text":1199},{"id":1216,"depth":94,"text":1217},{"id":1274,"depth":94,"text":2431},"13. Use Arc::clone Carefully",{"id":1288,"depth":94,"text":2433},"14. mem::replace and mem::take",{"id":1350,"depth":94,"text":1351},{"id":1478,"depth":94,"text":2436},"16. Cow to Avoid Allocations",{"id":1571,"depth":94,"text":1572},{"id":1661,"depth":94,"text":1662},{"id":1675,"depth":94,"text":2440},"19. Use &'static Where Appropriate",{"id":1686,"depth":94,"text":1687},{"id":1748,"depth":81,"text":2443},"release Profile Pitfalls",{"id":1800,"depth":81,"text":1801},{"id":2015,"depth":81,"text":2018},{"id":2061,"depth":81,"text":2062},{"id":2094,"depth":81,"text":2095},{"id":2273,"depth":81,"text":2274},{"id":2300,"depth":81,"text":2450},"std::alloc Layout",{"id":2319,"depth":81,"text":2320},{"id":2354,"depth":81,"text":2355},"md",{},"\u002Frust\u002F31-performance",{"title":5,"description":16},"rust\u002F31-performance","Bw0aHn-N6aF7JwUrcnabDDkxeCF6g1Ru-Z-pinnG24s",1785944093280]