๐™Ž๐™ช๐™ฅ๐™š๐™ง ๐™๐™–๐™จ๐™ฉ ๐™Ž๐™ฎ๐™จ๐™ฉ๐™š๐™ข๐™จ ๐™‹๐™ง๐™ค๐™œ๐™ง๐™–๐™ข๐™ข๐™ž๐™ฃ๐™œ


lapla

https://slide.lapla.dev/external/
labsyouth/fast_syspro(.pdf)
๐™Ž๐™ช๐™ฅ๐™š๐™ง ๐™๐™–๐™จ๐™ฉ ๐™Ž๐™ฎ๐™จ๐™ฉ๐™š๐™ข๐™จ ๐™‹๐™ง๐™ค๐™œ๐™ง๐™–๐™ข๐™ข๐™ž๐™ฃ๐™œ @ ใ‚ตใ‚คใƒœใ‚ฆใ‚บใƒปใƒฉใƒœใƒฆใƒผใ‚นๅคๅˆๅฎฟ2026
whoami
  • lapla
  • ๆ‰€ๅฑž: M2 @ ็ญ‘ๆณขๅคงๅญฆ, SWE @ SpaceXAI (a division of SpaceX) etc.
  • ใƒฉใƒœใƒฆใƒผใ‚นใฏ14ๆœŸไฟฎไบ†
  • Improving the Rust ecosystem ๐Ÿฆ€
    • ไธปใซRustใ‚ณใƒณใƒ‘ใ‚คใƒฉ (rustc), ไธ–็•Œๆœ€้€Ÿใฎใƒชใƒณใ‚ซใƒผ
      (wild๏ผŒใƒกใƒณใƒ†ใƒŠใƒผ), ใƒชใƒณใ‚ฟใƒผ (clippy)
  • Links
๐™Ž๐™ช๐™ฅ๐™š๐™ง ๐™๐™–๐™จ๐™ฉ ๐™Ž๐™ฎ๐™จ๐™ฉ๐™š๐™ข๐™จ ๐™‹๐™ง๐™ค๐™œ๐™ง๐™–๐™ข๐™ข๐™ž๐™ฃ๐™œ @ ใ‚ตใ‚คใƒœใ‚ฆใ‚บใƒปใƒฉใƒœใƒฆใƒผใ‚นๅคๅˆๅฎฟ2026
What
  • ๅ€‹ไบบ็š„ใซใ“ใ“1ๅนดๅผท๏ผˆไธปใซRustใง๏ผ‰ใ„ใใคใ‹ใฎใ‚ฝใƒ•ใƒˆใ‚ฆใ‚งใ‚ขใ‚’้ซ˜้€Ÿใซใ™ใ‚‹ๆฉŸไผšใŒใ‚ใฃใŸ
    • Wildใƒชใƒณใ‚ซใƒผ๏ผˆLinuxๅ‘ใ‘ใซใฏmoldใฎๆ•ฐๅ€๏ผŒ่‡ชๅˆ†ใŒไปŠๅคๆ‹…ๅฝ“ใ—ใŸWasmใƒใƒผใƒˆใงใฏwasm-ld (LLVM) ใฎๆ•ฐๅ€๏ฝžๅๆ•ฐๅ€้ซ˜้€Ÿ๏ผŽใฉใกใ‚‰ใ‚‚ๅคšๅˆ†ไธ–็•Œไธ€้ซ˜้€Ÿใชใƒชใƒณใ‚ซใƒผ๏ผ‰
    • ๆญฃ่ฆ่กจ็พใ‚จใƒณใ‚ธใƒณ๏ผˆใƒฏใƒผใ‚ฏใƒญใƒผใƒ‰ใซใ‚‚ใ‚ˆใ‚‹ใŒRustๅ…ฌๅผใฎๆŒใฃใฆใ„ใ‚‹ใ‚‚ใฎใ‚ˆใ‚Šๆ•ฐๅ€็จ‹ๅบฆ้ซ˜้€Ÿใซใงใใ‚‹ใ‚ฑใƒผใ‚นใŒใ‚ใ‚‹๏ผ‰
    • ๅˆ†ๆ•ฃใƒ•ใ‚กใ‚คใƒซใ‚ทใ‚นใƒ†ใƒ  at Preferred Networks Inc.๏ผˆ่ฉณ็ดฐใชๆ•ฐๅ€คใฏๅ…ฌ่กจใงใใชใ„ใŒ้€ŸใใชใฃใŸ๏ผ‰
  • ใใฎ้Ž็จ‹ใง้ซ˜้€Ÿใชใ‚ทใ‚นใƒ†ใƒ ใƒ—ใƒญใ‚ฐใƒฉใƒ ใ‚’ๆ›ธใใซใ‚ใŸใฃใฆ๏ผŒใฉใฎใ‚ˆใ†ใชใ“ใจใ‚’{ๆ„่ญ˜ใ™ใ‚‹ใจ่‰ฏใ„ใ‹๏ผŒ็–‘ใ†ใจ่‰ฏใ„ใ‹๏ผŒ้ฟใ‘ใ‚‹ใจ่‰ฏใ„ใ‹}ใชใฉใฎ็Ÿฅ่ฆ‹ใŒๆบœใพใฃใฆใใŸใฎใงใใฎไธ€้ƒจใ‚’ๆ”พๆต
    • ๅฝ“็„ถใชใŒใ‚‰้Š€ใฎๅผพไธธใงใฏใชใ„ใ—๏ผŒๅธธใซๆญฃใ—ใ„ใ‚ใ‘ใงใ‚‚ใชใ„
    • ไธ–ใฎไธญใซใฏๆง˜ใ€…ใช้ซ˜้€ŸๅŒ–ๆ‰‹ๆณ•ใŒใ‚ใ‚Š๏ผŒ้ฉใ™ใ‚‹ใ‚ทใƒŠใƒชใ‚ชใจใใ†ใงใชใ„ใ‚ทใƒŠใƒชใ‚ชใŒใ‚ใ‚Š๏ผŒใใ‚Œใ‚‰ๅ…จ้ƒจใฏ็ถฒ็พ…ใงใใชใ„๏ผˆใ ใ‹ใ‚‰"ไธ€้ƒจ"๏ผ‰
    • ใ‚ขใƒซใ‚ดใƒชใ‚บใƒ ใ‚’ๅทฅๅคซใ™ใ‚‹ใฎใฏๅคงๅ‰ๆ
  • ๅ‹•ไฝœ็’ฐๅขƒใจใ—ใฆLinuxใ‚’ๆƒณๅฎšใ—ใพใ™
๐™Ž๐™ช๐™ฅ๐™š๐™ง ๐™๐™–๐™จ๐™ฉ ๐™Ž๐™ฎ๐™จ๐™ฉ๐™š๐™ข๐™จ ๐™‹๐™ง๐™ค๐™œ๐™ง๐™–๐™ข๐™ข๐™ž๐™ฃ๐™œ @ ใ‚ตใ‚คใƒœใ‚ฆใ‚บใƒปใƒฉใƒœใƒฆใƒผใ‚นๅคๅˆๅฎฟ2026
Agenda

ใ‚ขใƒซใ‚ดใƒชใ‚บใƒ ใฎๆฌกใซ็–‘ใ†ๅฎŸ่ฃ…ไธŠใฎๅทฅๅคซใฎไธ€้ƒจใ‚’่ฉฑใ—ใŸใ„๏ผš

  1. "ๆญฃใ—ใ„"่จˆๆธฌใ‚’ใ™ใ‚‹
  2. ใ‚ญใƒฃใƒƒใ‚ทใƒฅใƒฉใ‚คใƒณใ‚’ๆ„่ญ˜ใ™ใ‚‹
  3. ๅฏ่ƒฝใชใ‚‰ใ‚ณใ‚นใƒˆใ‚’้š ่”ฝใ™ใ‚‹
  4. ไธ€่ฆ‹ไธฆๅˆ—ๅŒ–ใงใใชใใ†ใชใ‚‚ใฎใ‚’ไธฆๅˆ—ๅŒ–ใ™ใ‚‹
  5. ๅฎ‰ๆ˜“ใซๅŒๆœŸใƒ—ใƒชใƒŸใƒ†ใ‚ฃใƒ–ใซๆ‰‹ใ‚’ๅ‡บใ•ใชใ„
  6. ๅฐใ•ใ„ๅคง้‡ใฎใƒกใƒขใƒชใ‚ขใƒญใ‚ฑใƒผใ‚ทใƒงใƒณใ‚’้ฟใ‘ใ‚‹
  7. ้žๅŒๆœŸใฏCPU-heavyใชใ‚ฟใ‚นใ‚ฏใซใฏๅ‘ใ‹ใชใ„ใ“ใจใŒใ‚ใ‚‹
๐™Ž๐™ช๐™ฅ๐™š๐™ง ๐™๐™–๐™จ๐™ฉ ๐™Ž๐™ฎ๐™จ๐™ฉ๐™š๐™ข๐™จ ๐™‹๐™ง๐™ค๐™œ๐™ง๐™–๐™ข๐™ข๐™ž๐™ฃ๐™œ @ ใ‚ตใ‚คใƒœใ‚ฆใ‚บใƒปใƒฉใƒœใƒฆใƒผใ‚นๅคๅˆๅฎฟ2026
1๏ผš"ๆญฃใ—ใ„"่จˆๆธฌใ‚’ใ™ใ‚‹
  • ๅฝ“ใŸใ‚Šๅ‰ใ ใŒ้‡่ฆ๏ผŒใ‹ใคๆญฃใ—ใใƒ‘ใƒ•ใ‚ฉใƒผใƒžใƒณใ‚นๆธฌๅฎšใ‚’ใ™ใ‚‹ใฎใฏๆกˆๅค–้›ฃใ—ใ„๏ผˆใจๆ€ใ†๏ผ‰
    • ๅค–ไนฑใฎๅฝฑ้Ÿฟใ‚’ใฉใ“ใพใงๆŽ’้™คใงใใฆใ„ใ‚‹ใ‹๏ผŸ
      • CPUใฎๅ‘จๆณขๆ•ฐใฏไธ€ๅฎšใซใงใใฆใ„ใ‚‹ใ‹๏ผŸ1^1
      • I/Oๅ…ˆใฎใƒ•ใ‚กใ‚คใƒซใ‚ทใ‚นใƒ†ใƒ ใฎ้ธๅฎšใฏๅฆฅๅฝ“ใ‹๏ผŸ
      • ใƒšใƒผใ‚ธใ‚ญใƒฃใƒƒใ‚ทใƒฅใฏใฉใฎ็จ‹ๅบฆๆธฉใพใฃใฆใ„ใ‚‹ใ‹๏ผŸ
    • ๆธฌๅฎšๅ€คใฏๆบใ‚‰ใ„ใ ใ‚ณใƒผใƒŠใƒผใ‚ฑใƒผใ‚นใ‚’ๆ‹พใฃใฆใ„ใชใ„ใ‹๏ผŸ
    • ๆธฌๅฎšใƒใ‚คใƒณใƒˆใฎ่จญๅฎšใฎไป•ๆ–นใฏๅฆฅๅฝ“ใ‹๏ผŸ
      • ใƒœใƒˆใƒซใƒใƒƒใ‚ฏใจใชใ‚‹ๅŒบ้–“ใ‚’็‰นๅฎšใ™ใ‚‹ใฎใซๅฆฅๅฝ“ใช็ฒ’ๅบฆใซใชใฃใฆใ„ใ‚‹ใ‹๏ผŸ
    • ใƒ‡ใƒใƒƒใ‚ฐใƒ“ใƒซใƒ‰ใ‚„้–‹็™บ่€…ๅ‘ใ‘ใฎๆคœๆŸปใŒๆททใ–ใฃใฆใ„ใชใ„ใ‹
    • ใใ‚‚ใใ‚‚่€ƒๆ…ฎๅฏพ่ฑกใฏไธ€่ˆฌ็š„ใซ้ ป็™บใ—ใ†ใ‚‹ใ‚ˆใ†ใชใ‚ทใƒใƒฅใ‚จใƒผใ‚ทใƒงใƒณใŒใ‚ใ‚‹ใ‹๏ผŸ

1: ไพ‹ใˆใฐCPUใ‚’ใƒ‘ใƒ•ใ‚ฉใƒผใƒžใƒณใ‚นใƒขใƒผใƒ‰ใซใ™ใ‚‹ใจใ‹๏ผŒ/sys/devices/system/cpu/intel_pstate/min_perf_pctใงๆœ€ไฝŽๅ‘จๆณขๆ•ฐใ‚’็™พๅˆ†็އใง่จญๅฎšใงใใ‚‹๏ผˆIntel CPUใฎๅ ดๅˆ๏ผ‰ใฎใง100ใซ่จญๅฎšใ™ใ‚‹ใจใ‹ใฎๅทฅๅคซใŒใ‚ใ‚‹

๐™Ž๐™ช๐™ฅ๐™š๐™ง ๐™๐™–๐™จ๐™ฉ ๐™Ž๐™ฎ๐™จ๐™ฉ๐™š๐™ข๐™จ ๐™‹๐™ง๐™ค๐™œ๐™ง๐™–๐™ข๐™ข๐™ž๐™ฃ๐™œ @ ใ‚ตใ‚คใƒœใ‚ฆใ‚บใƒปใƒฉใƒœใƒฆใƒผใ‚นๅคๅˆๅฎฟ2026
1๏ผš"ๆญฃใ—ใ„"่จˆๆธฌใ‚’ใ™ใ‚‹๏ผˆ่จˆๆธฌใซไพฟๅˆฉใชใƒ„ใƒผใƒซ้”๏ผ‰

ใ‚ˆใ‚Š่‰ฏใ„่จˆๆธฌใ‚’ๆ”ฏๆดใ™ใ‚‹ใŸใ‚ใซๆง˜ใ€…ใชใƒ„ใƒผใƒซใŒใ‚ใ‚‹๏ผˆใ‚‚ใกใ‚ใ‚“ใ“ใ“ใซๆŒ™ใ’ใŸไปฅๅค–ใซใ‚‚๏ผ๏ผ‰

  • perf: ใ‹ใชใ‚Šๆœ‰ๅ๏ผŽๆง˜ใ€…ใชใƒ‘ใƒ•ใ‚ฉใƒผใƒžใƒณใ‚นใ‚ซใ‚ฆใƒณใ‚ฟใƒผใฎๅ€คใ‚’ๅ–ใ‚Œใ‚‹๏ผŽflamegraphใจใ‹ใ‚‚ใ“ใ‚Œ๏ผŽ
  • criterion-rs: ใƒฏใƒผใ‚ฏใƒญใƒผใƒ‰ใ‚’ไฝœๆˆใ—ใฆใใ‚Œใžใ‚Œใซๅฏพใ—ใฆๆœ‰ๆ„ใชๅทฎใŒๅ‡บใ‚‹ใ‹ใฉใ†ใ‹ใ‚’ๆคœ่จผใงใใ‚‹๏ผŽHTMLใงใƒฌใƒใƒผใƒˆใ‚‚่ฆ‹ใ‚‰ใ‚Œใ‚‹
  • hyperfine: ใ‹ใชใ‚Šๆœ‰ๅใฉใ“ใ‚๏ผŽๅฎŸ่กŒๆ™‚้–“ (wall time) ใ ใ‘ๆฌฒใ—ใ„ใชใ‚‰ใ“ใ‚Œใง่‰ฏใ„ๆฐ—ใŒใ™ใ‚‹
  • poop: Zigใฎไฝœ่€…Andrew Kelley่ฃฝ๏ผŽใƒกใƒขใƒชไฝฟ็”จ้‡ใ‚„ๅ‘ฝไปคๆ•ฐไปฅๅค–ใซใ‚‚CPUใ‚ญใƒฃใƒƒใ‚ทใƒฅใƒŸใ‚นใ‚„ๅˆ†ๅฒใƒŸใ‚นๅ›žๆ•ฐใชใฉใพใงๅ–ใ‚Œใ‚‹
  • perfetto: Google่ฃฝ๏ผŽใƒ—ใƒญใ‚ฐใƒฉใƒ ไธญใซใƒˆใƒฌใƒผใ‚นใƒใ‚คใƒณใƒˆใ‚’ไป•่พผใ‚ใฆ https://ui.perfetto.dev ใซๅ…ฅใ‚Œใ‚‹ใจๅฏ่ฆ–ๅŒ–ใงใใ‚‹
  • dhat: ใƒ’ใƒผใƒ—็ขบไฟใ‚’่ฟฝ่ทกใงใใ‚‹ใƒกใƒขใƒชใ‚ขใƒญใ‚ฑใƒผใ‚ฟใƒผ๏ผŽRustใงใฎใ‚ฏใƒฌใƒผใƒˆใ‚‚ใ‚ใ‚‹๏ผŽ
๐™Ž๐™ช๐™ฅ๐™š๐™ง ๐™๐™–๐™จ๐™ฉ ๐™Ž๐™ฎ๐™จ๐™ฉ๐™š๐™ข๐™จ ๐™‹๐™ง๐™ค๐™œ๐™ง๐™–๐™ข๐™ข๐™ž๐™ฃ๐™œ @ ใ‚ตใ‚คใƒœใ‚ฆใ‚บใƒปใƒฉใƒœใƒฆใƒผใ‚นๅคๅˆๅฎฟ2026
2: ใ‚ญใƒฃใƒƒใ‚ทใƒฅใƒฉใ‚คใƒณใ‚’ๆ„่ญ˜ใ™ใ‚‹
  • ็พไปฃใฎ่จˆ็ฎ—ๆฉŸใซใฏ่‡ณใ‚‹ใจใ“ใ‚ใซใ‚ญใƒฃใƒƒใ‚ทใƒฅใŒๅญ˜ๅœจใ™ใ‚‹
    • CPUใ ใ‘ใงใ‚‚L1, L2, L3, I-cache, D-cache, TLB, ๅˆ†ๅฒไบˆๆธฌ็ญ‰ใ€…
  • ใ‚ใพใ‚Šๆ™ฎๆฎตๆ„่ญ˜ใ™ใ‚‹ใ“ใจใฏใชใ„ใŒ๏ผŒๅฝ“็„ถใ‚ญใƒฃใƒƒใ‚ทใƒฅใซใฏๅฎน้‡ใŒใ‚ใ‚‹ใฎใงใ‚ญใƒฃใƒƒใ‚ทใƒฅใƒฉใ‚คใƒณใซไน—ใ‚Šใ‚„ใ™ใ„ใ‚ˆใ†ใชๆง‹้€ ใซใ™ใ‚‹ใจๅŠนใๅ ดๅˆใŒใ‚ใ‚‹
    • ไธ€้ƒจใฏใ‚ณใƒณใƒ‘ใ‚คใƒฉใŒloop interchange็ญ‰ใฎๅทฅๅคซใซใ‚ˆใ‚Šใ‚„ใฃใฆใใ‚Œใฆใ„ใ‚‹ๅ ดๅˆใŒใ‚ใ‚‹

ไพ‹๏ผš

  • ้ ป็นใซๅ‚็…งใ•ใ‚Œใ‚‹ๆง‹้€ ไฝ“ใฎใ‚ตใ‚คใ‚บใ‚’ๆŠ‘ใˆใ‚‹ใจ๏ผŒใƒกใƒขใƒชไธŠใงๅฐใ•ใๅฏ†้›†ใ•ใ›ใ‚‰ใ‚Œใ‚‹
  • ใ‚นใƒฌใƒƒใƒ‰ใ”ใจใซ่งฆใ‚‹ใ‚ขใƒˆใƒŸใƒƒใ‚ฏใ‚’ๅŒใ˜ใ‚ญใƒฃใƒƒใ‚ทใƒฅใƒฉใ‚คใƒณใซ็ฝฎใใจfalse sharingใง้…ใใชใ‚‹๏ผˆใฎใง้€†ใซใƒ‘ใƒ‡ใ‚ฃใƒณใ‚ฐใ—ใฆๅคงใใใ™ใ‚‹๏ผ‰

ใ“ใฎใ‚ˆใ†ใชๆ„Ÿใ˜ใงใƒ‡ใƒผใ‚ฟใฎๆŒใกๆ–นใ‚’ๅค‰ใˆใฆๅŠน็އ็š„ใซใชใ‚‹ไพ‹ใจใ—ใฆAoSใจSoAใ‚’็ดนไป‹

๐™Ž๐™ช๐™ฅ๐™š๐™ง ๐™๐™–๐™จ๐™ฉ ๐™Ž๐™ฎ๐™จ๐™ฉ๐™š๐™ข๐™จ ๐™‹๐™ง๐™ค๐™œ๐™ง๐™–๐™ข๐™ข๐™ž๐™ฃ๐™œ @ ใ‚ตใ‚คใƒœใ‚ฆใ‚บใƒปใƒฉใƒœใƒฆใƒผใ‚นๅคๅˆๅฎฟ2026
2: ใ‚ญใƒฃใƒƒใ‚ทใƒฅใƒฉใ‚คใƒณใ‚’ๆ„่ญ˜ใ™ใ‚‹๏ผˆAoSใจSoA๏ผ‰
  • AoS (Array of Structures):
struct Point {
    float x, y, z; // ็‚นใ”ใจใซ x, y, z ใ‚’ใพใจใ‚ใ‚‹
};

Point points[3] = {
    {x1, y1, z1},
    {x2, y2, z2},
    {x3, y3, z3}
}; // x1, y1, z1, x2, y2, z2, x3, y3, z3 ใฎ้ †ใซใƒกใƒขใƒชใซไธฆใถ
  • SoA (Structure of Arrays):
struct Points { // ๅฑžๆ€งใ”ใจใซใพใจใ‚ใ‚‹
    vector<float> x;
    vector<float> y;
    vector<float> z;
}; // x1, x2, x3, y1, y2, y3, z1, z2, z3 ใฎ้ †ใซใƒกใƒขใƒชใซไธฆใถ
๐™Ž๐™ช๐™ฅ๐™š๐™ง ๐™๐™–๐™จ๐™ฉ ๐™Ž๐™ฎ๐™จ๐™ฉ๐™š๐™ข๐™จ ๐™‹๐™ง๐™ค๐™œ๐™ง๐™–๐™ข๐™ข๐™ž๐™ฃ๐™œ @ ใ‚ตใ‚คใƒœใ‚ฆใ‚บใƒปใƒฉใƒœใƒฆใƒผใ‚นๅคๅˆๅฎฟ2026
2: ใ‚ญใƒฃใƒƒใ‚ทใƒฅใƒฉใ‚คใƒณใ‚’ๆ„่ญ˜ใ™ใ‚‹๏ผˆAoSใจSoA 2๏ผ‰
  • AoSใฏๅ„ใ‚ชใƒ–ใ‚ธใ‚งใ‚ฏใƒˆใฎๅ…จๅฑžๆ€งใ‚’ใƒซใƒผใƒ—ๅ†…้ƒจใชใฉใงใพใจใ‚ใฆไฝฟใ†ๅ‡ฆ็†ใซใฏๅ‘ใ„ใฆใ„ใ‚‹
    • ๅ„ใƒกใƒณใƒใƒผใ‚’ไธ€ๆ‹ฌใงใ‚ญใƒฃใƒƒใ‚ทใƒฅใƒฉใ‚คใƒณใซ่ผ‰ใ›ใ‚„ใ™ใ„ใ‹ใ‚‰
  • ไธ€ๆ–นใง็‰นๅฎšใƒกใƒณใƒใƒผใ ใ‘ใ‚’ไธ€ๆ‹ฌๅ‡ฆ็†ใ™ใ‚‹้ƒจๅˆ†ใŒใ‚ใฃใฆ๏ผŒใใ“ใŒใƒ›ใƒƒใƒˆใ‚นใƒใƒƒใƒˆใฎๅ ดๅˆAoSใฏไธๅ‘ใ
    • ไพ‹ใˆใฐxใ ใ‘ใ‚’ไธ€ๆ‹ฌๅ‡ฆ็†ใ™ใ‚‹ใƒซใƒผใƒ—ใŒใ‚ใฃใŸๅ ดๅˆ๏ผŒSoAใฏx1, x2, x3ใ‚’้€ฃ็ถšใ—ใŸใ‚ญใƒฃใƒƒใ‚ทใƒฅใƒฉใ‚คใƒณใซ่ผ‰ใ›ใ‚‹ใ“ใจใŒใงใใ‚‹ใŒ๏ผŒAoSใฏx1, y1, z1ใจไธ่ฆใชๅ€คใŒใ‚ญใƒฃใƒƒใ‚ทใƒฅใซ่ผ‰ใ‚‹
    • SoAใฎๆ–นใŒSIMDๅŒ–ใ—ใ‚„ใ™ใ„
  • ่ฆใฏไฝฟใ„ๅˆ†ใ‘
  • ใ“ใฎๆ‰‹ใฎ่ญฐ่ซ–ใฏHPC็ณปใ ใจใพใ‚็››ใ‚“ใชๆฐ—ใŒใ™ใ‚‹
๐™Ž๐™ช๐™ฅ๐™š๐™ง ๐™๐™–๐™จ๐™ฉ ๐™Ž๐™ฎ๐™จ๐™ฉ๐™š๐™ข๐™จ ๐™‹๐™ง๐™ค๐™œ๐™ง๐™–๐™ข๐™ข๐™ž๐™ฃ๐™œ @ ใ‚ตใ‚คใƒœใ‚ฆใ‚บใƒปใƒฉใƒœใƒฆใƒผใ‚นๅคๅˆๅฎฟ2026
3: ๅฏ่ƒฝใชใ‚‰ใ‚ณใ‚นใƒˆใ‚’้š ่”ฝใ™ใ‚‹๏ผˆใ‚ฏใƒชใƒผใƒณใ‚ขใƒƒใƒ—ใ‚ณใ‚นใƒˆใฎ้š ่”ฝ๏ผ‰
  • ๆœฌไฝ“ใฎๅ‡ฆ็†็ต‚ไบ†ๅพŒใซไฝฟใ„็ต‚ใ‚ใฃใŸใƒกใƒขใƒช็ญ‰ใ‚’่งฃๆ”พใ™ใ‚‹ใ‚ฏใƒชใƒผใƒณใ‚ขใƒƒใƒ—ใฏๅ‰ฒใจๆ™‚้–“ใŒใ‹ใ‹ใ‚‹ใ“ใจใŒใ‚ใ‚‹๏ผˆๅคง้‡ใซmmap(2)ใ—ใฆใ„ใ‚‹ๅ ดๅˆใชใฉ๏ผ‰
  • ไพ‹ใˆใฐใปใจใ‚“ใฉๅ…จใฆใฎๅ‡ฆ็†ใ‚’fork(2)ใ—ใŸๅญใƒ—ใƒญใ‚ปใ‚นใฎไธญใง่กŒใ†ใจใ“ใ‚Œใ‚’่งฃๆถˆใงใใ‚‹ใ“ใจใŒใ‚ใ‚‹
    • ๆœฌไฝ“ใฎๅ‡ฆ็†ใŒ็ต‚ใ‚ใฃใŸใ‚‰่ฆชใซๅพฉๅธฐใ™ใ‚‹๏ผŽใ‚ฏใƒชใƒผใƒณใ‚ขใƒƒใƒ—ใฎๅคง้ƒจๅˆ†ใฏๅญใƒ—ใƒญใ‚ปใ‚นใฎ่ฒฌๅ‹™ใซใชใ‚‹ใฎใงใใ‚Œใ‚‰ใฏใƒใƒƒใ‚ฏใ‚ฐใƒฉใ‚ฆใƒณใƒ‰ใงๅ‹ๆ‰‹ใซ่กŒใ‚ใ‚Œใ‚‹๏ผŽใƒฆใƒผใ‚ถใƒผใŒ่ช่ญ˜ใ™ใ‚‹็ต‚ไบ†ใฏ่ฆชใƒ—ใƒญใ‚ปใ‚นใฎ็ต‚ไบ†ๆ™‚็‚นใชใฎใงใ‚ฏใƒชใƒผใƒณใ‚ขใƒƒใƒ—ใ‚ณใ‚นใƒˆใ‚’้š ่”ฝใงใใ‚‹
๐™Ž๐™ช๐™ฅ๐™š๐™ง ๐™๐™–๐™จ๐™ฉ ๐™Ž๐™ฎ๐™จ๐™ฉ๐™š๐™ข๐™จ ๐™‹๐™ง๐™ค๐™œ๐™ง๐™–๐™ข๐™ข๐™ž๐™ฃ๐™œ @ ใ‚ตใ‚คใƒœใ‚ฆใ‚บใƒปใƒฉใƒœใƒฆใƒผใ‚นๅคๅˆๅฎฟ2026
3: ๅฏ่ƒฝใชใ‚‰ใ‚ณใ‚นใƒˆใ‚’้š ่”ฝใ™ใ‚‹๏ผˆใ‚ฏใƒชใƒผใƒณใ‚ขใƒƒใƒ—ใ‚ณใ‚นใƒˆใฎ้š ่”ฝๆ™‚ใฎๆณจๆ„๏ผ‰

ใŸใ ใ—fork(2)ใงใฎใ‚ฏใƒชใƒผใƒณใ‚ขใƒƒใƒ—ใ‚ณใ‚นใƒˆ้š ่”ฝใฏๆฌกใฎใ‚ˆใ†ใช็‚นใซๆณจๆ„ใ™ใ‚‹ๅฟ…่ฆใŒใ‚ใ‚‹

  • ่ฆชใŒใƒžใƒซใƒใ‚นใƒฌใƒƒใƒ‰ใ ใจfork(2)ใฏๅ‘ผใ‚“ใ ใ‚นใƒฌใƒƒใƒ‰ใ—ใ‹ใ‚ณใƒ”ใƒผใ—ใชใ„
    • ไป–ใ‚นใƒฌใƒƒใƒ‰ใŒๆŽดใ‚“ใ ใƒญใƒƒใ‚ฏใฎไธŠใงๆญปใซใ†ใ‚‹
  • ็ตๆžœใ‚’่ฆชใซ่ฟ”ใ™ๆ‰‹ๆฎต๏ผˆpipeใ‚„ๅ…ฑๆœ‰ใƒกใƒขใƒช๏ผ‰ใฏๅˆฅ้€”่ฆใ‚‹
  • ใƒกใƒขใƒชๆถˆ่ฒป้‡๏ผˆResident Set Size๏ผ‰ใ‚’ๆญฃใ—ใๆธฌๅฎšใงใใชใใชใ‚‹๏ผˆๅคงๆฆ‚ใฎใƒ„ใƒผใƒซใฏ่ฆชใƒ—ใƒญใ‚ปใ‚นใฎๆถˆ่ฒป้‡ใ‚’ๆธฌๅฎšใ™ใ‚‹ใ‹ใ‚‰๏ผ‰
    • ใƒ•ใ‚ฉใƒผใ‚ฏใ—ใชใ„ใ‚ชใƒ—ใ‚ทใƒงใƒณใ‚‚ๆŒใŸใ›ใฆใŠใ„ใฆRSSใ‚’่จˆๆธฌใ™ใ‚‹ใจใใซใฏใใกใ‚‰ใ‚’ไฝฟใ†ใฟใŸใ„ใชๆ–นๆณ•ใงๅ›ž้ฟใ™ใ‚‹ใจ่‰ฏใ•ใ’
๐™Ž๐™ช๐™ฅ๐™š๐™ง ๐™๐™–๐™จ๐™ฉ ๐™Ž๐™ฎ๐™จ๐™ฉ๐™š๐™ข๐™จ ๐™‹๐™ง๐™ค๐™œ๐™ง๐™–๐™ข๐™ข๐™ž๐™ฃ๐™œ @ ใ‚ตใ‚คใƒœใ‚ฆใ‚บใƒปใƒฉใƒœใƒฆใƒผใ‚นๅคๅˆๅฎฟ2026
4: ไธ€่ฆ‹ไธฆๅˆ—ๅŒ–ใงใใชใใ†ใชใ‚‚ใฎใ‚’ไธฆๅˆ—ๅŒ–ใ™ใ‚‹

ๆฌกใฎใ‚ˆใ†ใชๅ‡ฆ็†ใ‚’่€ƒใˆใ‚‹๏ผš

ids = {}
for x in items: # ใ“ใ“ใฎใƒซใƒผใƒ—ๅ›žๆ•ฐใŒใจใฆใ‚‚ๅคšใ„
    k = key(x)
    if k not in ids:
        ids[k] = size(ids)      # ๅˆๅ‡บ้ †ใซ ID ใ‚’ๆŒฏใ‚‹
    do_something(x, ids[k])
  • ใ“ใ‚Œใฏไธฆๅˆ—ๅŒ–ใ•ใ‚Œใฆใ„ใชใ„ใ—๏ผŒใ—ใŸใใฆใ‚‚ใƒŠใ‚คใƒผใƒ–ใซใฏใงใใชใ„
    • idsใŒใƒซใƒผใƒ—ใ‚’่ทจใ„ใงๆ›ดๆ–ฐใ•ใ‚Œใ‚‹ใฎใง๏ผŒๆฌกใฎใƒซใƒผใƒ—ใงไฝฟใ‚ใ‚Œใ‚‹ใƒ‡ใƒผใ‚ฟใŒๅ‰ใฎใƒซใƒผใƒ—ใ‚’่ฆ‹็ต‚ใ‚ใฃใŸๅพŒใซใ—ใ‹ๆฑบใพใ‚‰ใชใ„ใ‹ใ‚‰
    • ใƒซใƒผใƒ—ๅ†…ๅดใฎๅ‡ฆ็†ใŒ่ปฝใใฆใ‚‚ไปถๆ•ฐใจใฎๆŽ›ใ‘็ฎ—ใงใƒœใƒˆใƒซใƒใƒƒใ‚ฏใซใชใ‚‹ๅ ดๅˆใŒใ‚ใ‚‹
  • ๅฎŸ้š›ใซไปŠๅ›žๅฟ…่ฆใชใฎใฏๅ„ใ‚ญใƒผใŒๆœ€ๅˆใซๅ‡บ็พใ—ใŸไฝ็ฝฎ
๐™Ž๐™ช๐™ฅ๐™š๐™ง ๐™๐™–๐™จ๐™ฉ ๐™Ž๐™ฎ๐™จ๐™ฉ๐™š๐™ข๐™จ ๐™‹๐™ง๐™ค๐™œ๐™ง๐™–๐™ข๐™ข๐™ž๐™ฃ๐™œ @ ใ‚ตใ‚คใƒœใ‚ฆใ‚บใƒปใƒฉใƒœใƒฆใƒผใ‚นๅคๅˆๅฎฟ2026
4: ไธ€่ฆ‹ไธฆๅˆ—ๅŒ–ใงใใชใใ†ใชใ‚‚ใฎใ‚’ไธฆๅˆ—ๅŒ–ใ™ใ‚‹๏ผˆMap-Reduceใƒ‘ใ‚ฟใƒผใƒณ๏ผ‰
  • ๅฎŸใฏๅ…ˆ่ฟฐใฎใ‚ˆใ†ใชใƒ‘ใ‚ฟใƒผใƒณใงใ‚‚ไธ€้ƒจใ‚’ไธฆๅˆ—ๅŒ–ๅฏ่ƒฝ โ†’ Map-Reduce
  • ๅ˜ไธ€ใฎๅ…ฑๆœ‰็Šถๆ…‹ใ‚’ๅ–ใ‚Šๅ›žใ™ใ‹ใ‚‰ไธฆๅˆ—ๅŒ–ใงใใชใ„ใฎใง๏ผŒไพๅญ˜้–ขไฟ‚ใŒใ‚ใ‚‹้ƒจๅˆ†ใ‚’ๅ…ˆใซ่งฃๆฑบใ™ใ‚‹
    • Mapใง่ฆ็ด ใ”ใจใซ(ไธญ้–“key, ไธญ้–“value)ใฎใƒšใ‚ขใซใ™ใ‚‹๏ผŒGroup-byใงๅŒใ˜ไธญ้–“keyใ‚’ๅŽ้›†ใ—ใฆReduceใง้›†็ด„ใ™ใ‚‹
  • ๆฎ‹ใ‚‹้€ๆฌกใฏๅˆๅ‡บไฝ็ฝฎใงใ‚ฝใƒผใƒˆใ—ใฆ0..nใฎIDใ‚’ๆŒฏใ‚‹ใจใ“ใ‚๏ผˆใƒฆใƒ‹ใƒผใ‚ฏใ‚ญใƒผๆ•ฐใ ใ‘๏ผ‰๏ผŽdo_something()ใฏIDใƒ†ใƒผใƒ–ใƒซใ‚’่ฆ‹ใฆไธฆๅˆ—ใซใงใใ‚‹
๐™Ž๐™ช๐™ฅ๐™š๐™ง ๐™๐™–๐™จ๐™ฉ ๐™Ž๐™ฎ๐™จ๐™ฉ๐™š๐™ข๐™จ ๐™‹๐™ง๐™ค๐™œ๐™ง๐™–๐™ข๐™ข๐™ž๐™ฃ๐™œ @ ใ‚ตใ‚คใƒœใ‚ฆใ‚บใƒปใƒฉใƒœใƒฆใƒผใ‚นๅคๅˆๅฎฟ2026
5: ๅฎ‰ๆ˜“ใซๅŒๆœŸใƒ—ใƒชใƒŸใƒ†ใ‚ฃใƒ–ใซๆ‰‹ใ‚’ๅ‡บใ•ใชใ„
  • ๅฎŒไบ†้€š็Ÿฅใ‚„ไธ€ๅบฆใใ‚ŠใฎๅˆๆœŸๅŒ–ใฎใŸใ‚ใซmutexใ‚’ๆŒใกใŒใก
  • ใƒ•ใƒฉใ‚ฐ1ๆœฌใง่ถณใ‚Šใ‚‹ใชใ‚‰AtomicBoolใ‚„OnceLockใฎๆ–นใŒๅฎ‰ใ„ใ“ใจใŒๅคšใ„
static DONE: AtomicBool = AtomicBool::new(false);
DONE.store(true, Ordering::Release);            // ๅฎŒไบ†ๅด
while !DONE.load(Ordering::Acquire) { ... }     // ๅพ…ใกๅด
  • ่ค‡ๆ•ฐใƒ‡ใƒผใ‚ฟใ‚’ใพใจใ‚ใฆไธๅค‰ๆกไปถใ‚’ๅฎˆใ‚‹ใชใ‚‰mutexใฎใพใพใฎๆ–นใŒ่‰ฏใ„ใ—๏ผŒ้•ทใ„ๅพ…ใกใฎใจใใซใ‚นใƒ”ใƒณใ™ใ‚‹ใจCPUใ‚’็„ผใใฎใงไธๅˆฉ
๐™Ž๐™ช๐™ฅ๐™š๐™ง ๐™๐™–๐™จ๐™ฉ ๐™Ž๐™ฎ๐™จ๐™ฉ๐™š๐™ข๐™จ ๐™‹๐™ง๐™ค๐™œ๐™ง๐™–๐™ข๐™ข๐™ž๐™ฃ๐™œ @ ใ‚ตใ‚คใƒœใ‚ฆใ‚บใƒปใƒฉใƒœใƒฆใƒผใ‚นๅคๅˆๅฎฟ2026
6: ๅฐใ•ใ„ๅคง้‡ใฎใƒกใƒขใƒชใ‚ขใƒญใ‚ฑใƒผใ‚ทใƒงใƒณใ‚’้ฟใ‘ใ‚‹
  • ๅฐใ•ใๅคง้‡ใซใƒกใƒขใƒชใ‚’็ขบไฟใ™ใ‚‹ใ‚ˆใ‚Šใฏๅคงใใช้ ˜ๅŸŸใ‚’็ขบไฟใ—ใฆๅฟ…่ฆใซๅฟœใ˜ใฆๆ‰•ใ„ๅ‡บใ™ๆ–นใŒ้€Ÿใ„ๅ ดๅˆใŒๅคšใ„
    • ๅฐใ•ใ„malloc(2)ใฏใƒญใƒƒใ‚ฏใƒปใƒกใ‚ฟใƒ‡ใƒผใ‚ฟใƒปใ‚ญใƒฃใƒƒใ‚ทใƒฅไธ้€ฃ็ถš
  • ใ‚ทใ‚นใƒ†ใƒ ใƒ—ใƒญใ‚ฐใƒฉใƒ ใฏๅŒใ˜ๅฏฟๅ‘ฝใฎใ‚ชใƒ–ใ‚ธใ‚งใ‚ฏใƒˆใŒๅคง้‡ใซใชใ‚ŠใŒใก๏ผˆIR๏ผŒใƒ‘ใƒผใ‚น็ตๆžœ๏ผŒใƒžใƒƒใƒ็Šถๆ…‹...๏ผ‰
  • ใ‚ขใƒชใƒผใƒŠ๏ผšๆœ€ๅˆใซๅคงใใๅ–ใฃใฆใใ“ใ‹ใ‚‰ๆ‰•ใ„ๅ‡บใ™๏ผŽๅ€‹ๅˆฅใซfree(3)ใ—ใชใ„
    • bump allocatorใฏใใฎไธ€็•ชๅ˜็ด”ใชๅฎŸ่ฃ…๏ผˆ่ฆๆฑ‚ใŒๆฅใŸใ‚‰ใƒกใƒขใƒชใƒ—ใƒผใƒซๅ†…ใฎๆœชไฝฟ็”จ้ ˜ๅŸŸใ‚’ๆŒ‡ใ™ใƒใ‚คใƒณใ‚ฟใ‚’่ฆๆฑ‚ใ‚ตใ‚คใ‚บๅˆ†ใ ใ‘ๅ‰ๆ–นใซ็งปๅ‹•ใ•ใ›ใฆๆˆปใ‚‰ใชใ„๏ผŽใƒ‘ใƒผใ‚ตใƒผใจใ‹ใซใ‚ˆใไฝฟใ‚ใ‚ŒใŒใก๏ผŸ๏ผ‰
    • ๅฏฟๅ‘ฝใฎ็ต‚ใ‚ใ‚Šใซใพใจใ‚ใฆๆจใฆใ‚‹๏ผŽใ‚นใƒฌใƒƒใƒ‰ใ”ใจใซใƒใƒณใƒ—ใ™ใ‚‹ใจ็ขบไฟใƒ‘ใ‚นใ‹ใ‚‰ใƒญใƒƒใ‚ฏใŒๆถˆใˆใ‚‹
๐™Ž๐™ช๐™ฅ๐™š๐™ง ๐™๐™–๐™จ๐™ฉ ๐™Ž๐™ฎ๐™จ๐™ฉ๐™š๐™ข๐™จ ๐™‹๐™ง๐™ค๐™œ๐™ง๐™–๐™ข๐™ข๐™ž๐™ฃ๐™œ @ ใ‚ตใ‚คใƒœใ‚ฆใ‚บใƒปใƒฉใƒœใƒฆใƒผใ‚นๅคๅˆๅฎฟ2026
7: ้žๅŒๆœŸใฏCPU-heavyใชใ‚ฟใ‚นใ‚ฏใซใฏๅ‘ใ‹ใชใ„ใ“ใจใŒใ‚ใ‚‹
  • asyncใฏๅพ…ใกใฎๅคš้‡ๅŒ–ใงใ‚ใฃใฆ๏ผŒ่จˆ็ฎ—ใใฎใ‚‚ใฎใ‚’้€Ÿใใฏใ—ใชใ„
    • CPU-heavyใชไป•ไบ‹ใ‚’executorไธŠใงๅ›žใ™ใจไป–ใ‚ฟใ‚นใ‚ฏใŒๆญขใพใ‚‹
    • ใใ†ใ„ใ†ไป•ไบ‹ใฏใ‚นใƒฌใƒƒใƒ‰ใƒ—ใƒผใƒซใซๆŠ•ใ’ใฆ๏ผŒ็ตๆžœใ ใ‘channelใงๅ—ใ‘ใ‚‹ใชใฉใฎไปฃๆกˆใŒ่€ƒใˆใ‚‰ใ‚Œใ‚‹
  • ็‰นใซRustใงใฏasync / awaitใฏใ‚ณใƒณใƒ‘ใ‚คใƒฉใซใ‚ˆใฃใฆFutureใƒˆใƒฌใ‚คใƒˆใ‚’ๅฎŸ่ฃ…ใ—ใŸ็Šถๆ…‹ๆฉŸๆขฐ๏ผˆenum๏ผ‰ใซๅค‰ๆ›ใ•ใ‚Œใ‚‹
    • ExecutorใŒpollใ™ใ‚‹ใจ็Šถๆ…‹้ท็งปใŒ่ตทใ“ใ‚‹๏ผŽๅ„็Šถๆ…‹ใซใฏใใฎๆ™‚็‚นใง็”Ÿๅญ˜ใ—ใฆใ„ใ‚‹ใƒญใƒผใ‚ซใƒซๅค‰ๆ•ฐใŒไฟๆŒใ•ใ‚Œใฆใ„ใ‚‹
    • pollใฎใŸใณใซใใ‚Œใ‚‰ใ‚’stash / restoreใ™ใ‚‹ใฎใงmov็›ธๅฝ“ใŒๅข—ใˆใ‚‹
    • ่จ€่ชžใซใ‚ˆใฃใฆ้žๅŒๆœŸใฎๅฎŸ่ฃ…ใฏ้•ใ†๏ผˆGoใฎgoroutine๏ผŒJSใฎใ‚ณใƒผใƒซใ‚นใ‚ฟใƒƒใ‚ฏใจ{ใƒžใ‚ฏใƒญ, ใƒžใ‚คใ‚ฏใƒญ}ใ‚ฟใ‚นใ‚ฏใ‚ญใƒฅใƒผใชใฉ๏ผ‰๏ผŽใ“ใฎใ‚ณใ‚นใƒˆใƒขใƒ‡ใƒซใฏRustใฎ่ฉฑ
  • WebใฎI/Oๅพ…ใกใจใ‹ใชใ‚‰่ฉฑใฏๅˆฅ๏ผŽๆ™ฎ้€šใซๅ‘ใใจๆ€ใ†
๐™Ž๐™ช๐™ฅ๐™š๐™ง ๐™๐™–๐™จ๐™ฉ ๐™Ž๐™ฎ๐™จ๐™ฉ๐™š๐™ข๐™จ ๐™‹๐™ง๐™ค๐™œ๐™ง๐™–๐™ข๐™ข๐™ž๐™ฃ๐™œ @ ใ‚ตใ‚คใƒœใ‚ฆใ‚บใƒปใƒฉใƒœใƒฆใƒผใ‚นๅคๅˆๅฎฟ2026
ใพใจใ‚
  • ๏ผˆใ‚ทใ‚นใƒ†ใƒ ๏ผ‰ใƒ—ใƒญใ‚ฐใƒฉใƒ ใ‚’้ซ˜้€Ÿใซใ™ใ‚‹ใซใฏใ‚ขใƒซใ‚ดใƒชใ‚บใƒ ไปฅๅค–ใซใ‚‚ๆง˜ใ€…ใชๅทฅๅคซใŒ่€ƒใˆใ‚‰ใ‚Œ๏ผŒใใฎไธ€้ƒจใ‚’็ดนไป‹
    • ๆญฃใ—ใๆธฌใ‚Œใฆใ„ใ‚‹ใ‹๏ผˆCPUๅ‘จๆณขๆ•ฐ๏ผŒใƒ•ใ‚กใ‚คใƒซใ‚ทใ‚นใƒ†ใƒ ๏ผŒใƒšใƒผใ‚ธใ‚ญใƒฃใƒƒใ‚ทใƒฅ๏ผŒๅŒบ้–“ etc...๏ผ‰
    • ใƒ›ใƒƒใƒˆใชใƒ‡ใƒผใ‚ฟใฏใ‚ญใƒฃใƒƒใ‚ทใƒฅใซไน—ใ‚‹ใ‹๏ผˆAoS / SoA๏ผŒfalse sharing๏ผ‰
    • ็ต‚ไบ†ๅ‡ฆ็†ใ‚’ใƒฆใƒผใ‚ถใƒผใ‹ใ‚‰้š ่”ฝใงใใชใ„ใ‹
    • ่ฆ‹ใ‹ใ‘ไธŠ้€ๆฌกใชใƒซใƒผใƒ—ใฎๆœฌๅฝ“ใฎไพๅญ˜ใฏไฝ•ใ‹
    • mutexใฎไธญ่บซใฏๆœฌๅฝ“ใซใƒญใƒƒใ‚ฏใŒ่ฆใ‚‹ใ‹
    • ๅฐใ•ใ„malloc(2)ใ‚’้€ฃ็™บใ—ใฆใ„ใชใ„ใ‹
    • CPU-heavyใชไป•ไบ‹ใซใ‚„ใŸใ‚‰ใจasyncใ‚’ไฝฟใฃใฆใ„ใชใ„ใ‹
  • ใƒ—ใƒญใ‚ฐใƒฉใƒ ใŒ๐™จ๐™ช๐™ฅ๐™š๐™ง ๐™›๐™–๐™จ๐™ฉใ ใจ๐™š๐™ซ๐™š๐™ง๐™ฎ๐™ค๐™ฃ๐™šใŒ๐™๐™–๐™ฅ๐™ฅ๐™ฎ
๐™Ž๐™ช๐™ฅ๐™š๐™ง ๐™๐™–๐™จ๐™ฉ ๐™Ž๐™ฎ๐™จ๐™ฉ๐™š๐™ข๐™จ ๐™‹๐™ง๐™ค๐™œ๐™ง๐™–๐™ข๐™ข๐™ž๐™ฃ๐™œ @ ใ‚ตใ‚คใƒœใ‚ฆใ‚บใƒปใƒฉใƒœใƒฆใƒผใ‚นๅคๅˆๅฎฟ2026

Thanks for listening!

๐™Ž๐™ช๐™ฅ๐™š๐™ง ๐™๐™–๐™จ๐™ฉ ๐™Ž๐™ฎ๐™จ๐™ฉ๐™š๐™ข๐™จ ๐™‹๐™ง๐™ค๐™œ๐™ง๐™–๐™ข๐™ข๐™ž๐™ฃ๐™œ @ ใ‚ตใ‚คใƒœใ‚ฆใ‚บใƒปใƒฉใƒœใƒฆใƒผใ‚นๅคๅˆๅฎฟ2026

Super Fast Systems Programming lapla

whoami - lapla - Affiliation: M2 @ University of Tsukuba, SWE @ SpaceXAI (a division of SpaceX) etc. - Completed LabsYouth 14th term - Improving the Rust ecosystem ๐Ÿฆ€ - Mainly the Rust compiler (rustc), the world's fastest linker (wild, maintainer), and the linter (clippy) - Links - ๐•: @lapla_cogito - GitHub: @lapla-cogito - Other affiliations etc.: https://lapla.dev/about

What - Over the past year or so I have personally had opportunities to speed up several pieces of software (mainly in Rust) - [Wild linker](https://github.com/wild-linker/wild) (several times faster than mold on Linux; the Wasm port I worked on this summer is several to more than ten times faster than wasm-ld (LLVM). Both are probably the world's fastest linkers) - [Regex engine](https://github.com/lapla-cogito/rustegex) (depending on the workload, there are cases where it can be several times faster than the official Rust one) - Distributed file system at Preferred Networks Inc. (I cannot publish detailed numbers, but it got faster) - Through that process I have accumulated some knowledge about what to keep in mind, what to suspect, and what to avoid when writing fast systems programs, so I will share part of it - Of course this is not a silver bullet, and it is not always correct - There are many speedup techniques in the world, with scenarios they fit and scenarios they do not; I cannot cover all of them (hence "part of it") - Improving the algorithm is a given - We assume Linux as the runtime environment

Agenda I want to talk about some implementation techniques to look at after the algorithm: 1. Measure "correctly" 2. Be aware of cache lines 3. Hide costs when possible 4. Parallelize things that do not look parallelizable 5. Do not casually reach for synchronization primitives 6. Avoid large numbers of small memory allocations 7. Async can be a poor fit for CPU-heavy tasks

1: Measure "correctly" - Obvious but important, and I think measuring performance correctly is surprisingly hard - How far have you excluded external disturbance? - Is the CPU frequency held constant?$^1$ - Is the choice of filesystem for I/O appropriate? - How warm is the page cache? - Are the measurements picking up shaken corner cases? - Is the way measurement points are set appropriate? - Is the granularity appropriate for identifying the bottleneck interval? - Are debug builds or developer-oriented checks mixed in? - Does the thing under consideration even occur frequently in typical situations? > 1: For example, putting the CPU in performance mode, or setting the minimum frequency as a percentage via `/sys/devices/system/cpu/intel_pstate/min_perf_pct` (for Intel CPUs) to 100

1: Measure "correctly" (handy tools for measurement) There are various tools that help you measure better (and of course many besides the ones listed here!) - [perf](https://perfwiki.github.io/main/): Quite well known. Can collect values from various performance counters. Flamegraphs too. - [criterion-rs](https://github.com/criterion-rs/criterion.rs): Lets you create workloads and check whether a significant difference appears for each. You can also view reports in HTML. - [hyperfine](https://github.com/sharkdp/hyperfine): A fairly well-known one. If you just want wall time, this is probably enough. - [poop](https://github.com/andrewrk/poop): By Andrew Kelley, the author of Zig. Besides memory usage and instruction counts, it can also collect CPU cache misses, branch misses, and more. - [perfetto](https://perfetto.dev/): By Google. You can plant trace points in the program and visualize them at https://ui.perfetto.dev - [dhat](https://valgrind.org/docs/manual/dh-manual.html): A memory allocator that can track heap allocations. There is also a [crate](https://github.com/nnethercote/dhat-rs) for Rust.

2: Be aware of cache lines - Modern computers have caches everywhere - Even just on the CPU: L1, L2, L3, I-cache, D-cache, TLB, branch prediction, and so on - We do not usually think about it day to day, but of course caches have limited capacity, so structuring data so that it fits cache lines well can help - In some cases the compiler already does this via techniques such as loop interchange Examples: - Keeping frequently accessed structs small lets you pack them densely in memory - Putting atomics touched by different threads on the same cache line slows things down via false sharing (so conversely you pad them to make them larger) As an example of becoming more efficient by changing how data is laid out, I will introduce AoS and SoA

2: Be aware of cache lines (AoS and SoA) - AoS (Array of Structures): ```cpp struct Point { float x, y, z; // group x, y, z per point }; Point points[3] = { {x1, y1, z1}, {x2, y2, z2}, {x3, y3, z3} }; // laid out in memory as x1, y1, z1, x2, y2, z2, x3, y3, z3 ``` - SoA (Structure of Arrays): ```cpp struct Points { // group by attribute vector<float> x; vector<float> y; vector<float> z; }; // laid out in memory as x1, x2, x3, y1, y2, y3, z1, z2, z3 ```

2: Be aware of cache lines (AoS and SoA 2) - AoS is a good fit for processing that uses all attributes of each object together, e.g. inside a loop - Because it is easy to load every member onto a cache line in one go - On the other hand, if there is a part that bulk-processes only a specific member and that part is a hotspot, AoS is a poor fit - For example, if there is a loop that bulk-processes only `x`, SoA can put `x1, x2, x3` on consecutive cache lines, whereas AoS loads unused values as `x1, y1, z1` - SoA is also easier to SIMD-ize - In short, use the right one for the job - This kind of discussion seems fairly active in HPC

3: Hide costs when possible (hiding cleanup costs) - Cleanup that frees used memory and so on after the main work finishes can take a fair amount of time (e.g. when you have a large number of `mmap(2)`s) - For example, doing almost all of the work inside a child process created with `fork(2)` can sometimes resolve this - When the main work is done, return to the parent. Most of the cleanup becomes the child process's responsibility and happens in the background on its own. The exit the user observes is the parent process exiting, so the cleanup cost can be hidden

3: Hide costs when possible (caveats when hiding cleanup costs) However, hiding cleanup costs with `fork(2)` requires attention to the following points - If the parent is multithreaded, `fork(2)` copies only the calling thread - You can die on a lock held by another thread - You separately need a way to return results to the parent (pipe or shared memory) - You can no longer measure memory consumption (Resident Set Size) correctly (most tools measure the parent process's consumption) - A good workaround is to also provide a no-fork option and use that when measuring RSS

4: Parallelize things that do not look parallelizable Consider processing like the following: ```py ids = {} for x in items: # this loop runs a very large number of times k = key(x) if k not in ids: ids[k] = size(ids) # assign IDs in first-seen order do_something(x, ids[k]) ``` - This is not parallelized, and naively you cannot parallelize it even if you want to - Because `ids` is updated across loop iterations, the data used by the next iteration is only determined after the previous iteration has finished looking - Even if the work inside the loop is light, multiplied by the number of items it can become a bottleneck - What we actually need here is the first-seen position of each key

4: Parallelize things that do not look parallelizable (Map-Reduce pattern) - In fact, even a pattern like the one above can be partly parallelized โ†’ Map-Reduce - It cannot be parallelized because a single shared state is being threaded through, so resolve the dependent part first - Map turns each element into an (intermediate key, intermediate value) pair; Group-by collects the same intermediate keys; Reduce aggregates them - The remaining sequential work is sorting by first-seen position and assigning IDs `0..n` (only as many as unique keys). `do_something()` can then run in parallel by looking up the ID table

5: Do not casually reach for synchronization primitives - People tend to reach for a mutex for completion notification or one-time initialization - If a single flag is enough, `AtomicBool` or `OnceLock` is often cheaper ```rust static DONE: AtomicBool = AtomicBool::new(false); DONE.store(true, Ordering::Release); // completer side while !DONE.load(Ordering::Acquire) { ... } // waiter side ``` - If you need to protect an invariant across multiple pieces of data together, keeping a mutex is better; and spinning during a long wait burns CPU, so it is a disadvantage

6: Avoid large numbers of small memory allocations - Allocating one large region and handing pieces out as needed is often faster than allocating lots of small pieces - Small `malloc(2)`s mean locks, metadata, and cache discontinuity - Systems programs tend to have large numbers of objects with the same lifetime (IR, parse results, match state, ...) - Arena: take a large chunk up front and hand it out from there. Do not `free(3)` individually - A bump allocator is the simplest implementation (when a request comes in, move the pointer into unused space in the memory pool forward by the requested size and never go back. Often used in parsers?) - Throw it all away at the end of the lifetime. Bumping per thread removes locks from the allocation path

7: Async can be a poor fit for CPU-heavy tasks - async is multiplexing waits; it does not make the computation itself faster - Running CPU-heavy work on the executor stalls other tasks - Alternatives include throwing that work onto a thread pool and receiving only the result over a channel - Especially in Rust, `async` / `await` is transformed by the compiler into a state machine (enum) that implements the `Future` trait - When the executor polls, a state transition happens. Each state holds the local variables that are alive at that point - Those are stashed / restored on every poll, so the number of `mov`-equivalents increases - Async implementations differ by language (Go's goroutines, JS's call stack and {macro, micro}task queues, etc.). This cost model is about Rust - Waiting on Web I/O is a different story. I think it is a good fit in the ordinary sense

Summary - To make (systems) programs fast, various techniques besides the algorithm can be considered; I introduced some of them - Are you measuring correctly? (CPU frequency, filesystem, page cache, intervals, etc.) - Does hot data fit in cache? (AoS / SoA, false sharing) - Can teardown be hidden from the user? - What is the real dependency in a loop that looks sequential? - Does what is inside the mutex actually need a lock? - Are you firing off lots of small `malloc(2)`s? - Are you overusing async for CPU-heavy work? - When programs are super fast, everyone is happy