Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
goのメモリアロケーターの話
Search
nasa
June 29, 2022
Technology
860
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
goのメモリアロケーターの話
https://bitkey.connpass.com/event/248608で10分LTしたやつ
。
Goのメモリアロケーターの構造について軽く話した。
nasa
June 29, 2022
More Decks by nasa
See All by nasa
難解な自己紹介プログラムを書く
nasa_desu
1
420
鉄は熱いうちに打て - Kaigi Effect LT大会
nasa_desu
2
620
リンカを変えてgo buildを 速く出来るか
nasa_desu
2
4k
RustでOS開発はじめの一歩
nasa_desu
8
7.7k
ログから学ぶgo build
nasa_desu
4
1.6k
GoとRust - 並行処理編
nasa_desu
5
4.2k
Other Decks in Technology
See All in Technology
企画を Software Factory-ready にする——開発が高速になったとき、PdMの仕事はどう変わったか
yachibit
1
250
freeeにおけるSoftware Factory
freee
PRO
0
440
野良MCPサーバーを排除せよ!MCPサーバーのガバナンス
yukiogawa
1
220
ガチで放置できるClaude Code実行環境の作り方.pdf
lamaglama39
5
9.4k
導入から定着へ ~コーディングエージェントを日常業務に組み込む実践知~
yukisakai1225
0
220
DevelopersIO 2026 Tokyo 現時点の衛星通信サービスの現状を整理してみる
maroon1st
0
280
Refining Active Record
shugo
0
230
freeeにおける AI を用いた ブラウザ動作確認の自動化の取り組み
freee
PRO
0
180
Claude Code on Bedrock で統制をかける小ネタ集/claude-code-bedrock-governance-tips
emiki
1
11k
顧客価値を追いかけたら、プライシングにたどり着いた
sansantech
PRO
2
940
macOS Golden Gate 時代のMac管理
tategami
0
140
[EMNLP26] RIGEL: Self-Distilled Score Adaptation for Image and Video Captioning Evaluation
keio_smilab
PRO
0
120
Featured
See All Featured
Visualization
eitanlees
153
17k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
230
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
120
120k
Test your architecture with Archunit
thirion
2
2.5k
Between Models and Reality
mayunak
4
500
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.4k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.4k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
The Cult of Friendly URLs
andyhume
79
7k
Documentation Writing (for coders)
carmenintech
77
5.6k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
580
Transcript
©2022 Wantedly, Inc. GoͷϝϞϦΞϩέʔλʔ Bitkey × Voicyओ࠵ ~ Goษڧձ ~
2022/06/29 nasa (Asan Kondo)
©2022 Wantedly, Inc. ࣗݾհ • nasa Ͱ͢ • Wantedly, inc.
৽ଔ2 • ਪનج൫ͷӡ༻ɾ։ൃ • σʔλαΠΤϯςΟετͷੜ࢈ੑര্͛ • কདྷͷເnasaͱ͍͏ϋϯυϧωʔϜΛ͗औΔ͜ͱ • GitHub: k-nas a • Twitter: nasa_desu • Zenn: nasa 🎉 🎉 🎉 🎉 🎉
©2022 Wantedly, Inc. -5ͷඪ • ϝϞϦΞϩέʔλʔ͕ԿΛ͍ͯ͠Δ͔͔Δ • GoݴޠͷΞϩέʔλͷߏ͕গ͔͠Δ • RuntimeύοέʔδΛ͍ͯΈΔʂͱ͍͏ؾ࣋ͪʹͳΔ
©2022 Wantedly, Inc. ࣍ 1. ϝϞϦΞϩέʔλʔͱ 2. GoͷϝϞϦΞϩέʔλʔͷઃܭ 3. ·ͱΊ
©2021 Wantedly, Inc. ϝϞϦΞϩέʔλʔͱʁ
©2022 Wantedly, Inc. • ༻ՄೳͳώʔϓϝϞϦͷཧΛߦ͏ ϓϩάϥϜʮ3byteͩ͘͞ʔ͍ʯ Ξϩέʔλʔʮ͍ɺ͓ͪʂ(3byteۭ͍ͯΔ͔Β͋ͦ͜Λฦͦ͏)ʯ ϝϞϦΞϩέʔλʔͱʁ
©2022 Wantedly, Inc. • ༻ՄೳͳώʔϓϝϞϦͷཧΛߦ͏ ଞͰ༻͍ͯ͠ΔϝϞϦΛฦͪ͠Ό͍͚ͳ͍ Ξϩέʔλʔະ༻ྖҬΛ͍ͬͯΔඞཁ͕͋Δ ղ์͞ΕͨϝϞϦΛ࠶ར༻͢Δ ϝϞϦΞϩέʔλʔͱʁ
©2022 Wantedly, Inc. ༨ஊIFBQ TUBDLͲͪΒ͕ΘΕ͍ͯΔ͔ package main import "fmt" func
main() { slice := make([]int64, 0, 0) fmt.Println(slice) c := make(chan string) fmt.Println(c) s := "string" fmt.Println(s) } :) % go build -gcflags '-m' alloc_playground.go # command-line-arguments ./alloc_playground.go:7:13: inlining call to fmt.Println ./alloc_playground.go:10:13: inlining call to fmt.Println ./alloc_playground.go:13:13: inlining call to fmt.Println ./alloc_playground.go:6:15: make([]int64, 0, 0) escapes to heap ./alloc_playground.go:7:13: slice escapes to heap ./alloc_playground.go:7:13: []interface {}{ ... } does not escape ./alloc_playground.go:10:13: []interface {}{ ... } does not escape ./alloc_playground.go:13:13: s escapes to heap ./alloc_playground.go:13:13: []interface {}{ ... } does not escape <autogenerated >: 1: .this does not escape • -gcflags “-m”Λ͚ͭΔͱ͔Δ
©2022 Wantedly, Inc. ਖ਼֬ʹϝϞϦΛฦ͚ͩ͢Ͱ͍͍ͷ͔ʁ • ਖ਼֬͞MustͰ࣍ͷ̎ͭٻ͍ͨ͠ • • ͍΄͏͕ͦΓΌخ͍͠ΑͶʂ
• அยԽ • ϝϞϦΛແବͳ͘ར༻͍ͨ͠ΑͶʂ
©2022 Wantedly, Inc. ਖ਼֬ʹϝϞϦΛฦ͚ͩ͢Ͱ͍͍ͷ͔ʁ • அยԽʹ͍ͭͯܰ͘͢ ϓϩάϥϜʮ8byteͩ͘͞ʔ͍ʯ ΞϩέʔλʔʮΕͰ͢ɺɺɺʯ
©2022 Wantedly, Inc. ਖ਼֬ʹϝϞϦΛฦ͚ͩ͢Ͱ͍͍ͷ͔ʁ • ༻ՄೳͳώʔϓϝϞϦͷཧΛߦ͏ • ߴͰஅยԽ͕ى͜ΓͮΒ͍Ξϩέʔλʔ͕ྑ͍
©2021 Wantedly, Inc. (PͷϝϞϦΞϩέʔλʔ
©2022 Wantedly, Inc. (PΞϩέʔλʔͷߏཁૉ • ͋ͱ͔Βৄ͘͠ݟ͍͕ͯͬ͘͘͟Γઆ໌ͯ͠ΈΔ • G : ΰϧʔνϯ
• mcache: OSεϨου͝ͱͷΩϟογϡ • mcentral: ۭ͖ྖҬΛཧ͢Δ • mheap: OS͔ΒϝϞϦΛऔಘ͠ཧ
©2022 Wantedly, Inc. • mcach e • mcacheϚϧνεϨουͰੑೳΛग़ͨ͢Ίʹଘࡏ • mcentral͔ΒϝϞϦͷׂ͕ߦΘΕΔ
• 1 threadʹ1mcacheͱ͍͏ߏͳͷͰϩοΫΛऔΒ ͳͯ҆͘શʹѻ͑Δ (PΞϩέʔλʔͷߏཁૉ
©2022 Wantedly, Inc. • mcentra l • mheap͔ΒϝϞϦׂ͕ߦΘΕΔ • (ຊϝϞϦͰͳ͍͕Ұ୴ંͬͯઆ໌͢Δ
) • ෳεϨου͔Βࢀর͞ΕΔͷͰϩοΫΛऔΔඞཁ͕͋Δ • ͕ॏཁͳͷͰϩοΫͷ୯Ґ࠷খʹͳΔΑ͏ʹઃܭ͞ Ε͍ͯΔ • mhea p • OS͔ΒϝϞϦΛಘΔ • ॏ͍ॲཧʹͳΔͷͰҰͰΨοπϦϝϞϦΛऔಘ͢Δ (PΞϩέʔλʔͷߏཁૉ
©2022 Wantedly, Inc. TQBO • OS͔Βऔಘͨ͠ϝϞϦ༧ΊܾΊΒΕͨαΠζʹ۠Β Εཧ͞ΕΔ • ͜ͷαΠζ͝ͱʹ۠ΒΕͨϝϞϦΛspanͱݺͿ •
mcache, mcentral͜ͷspanΛཧ͢Δ
©2022 Wantedly, Inc. TQBO • αΠζͲ͏ܾ·͍ͬͯΔͷ͔ ? • sizeclass.goʹఆٛͯ͋͠Δ •
࣮ࡍʹׂΓͯΒΕΔΦϒδΣΫ τ͜ͷαΠζϐολϦʹͳΒ ͳ͍ • ͋Δఔແବڐ༰͞Ε͍ͯΔ package runtime / / class bytes/obj bytes/span objects tail waste max waste min align / / 1 8 8192 1024 0 87.50% 8 / / 2 16 8192 512 0 43.75% 16 / / 3 24 8192 341 8 29.24% 8 / / 4 32 8192 256 0 21.88% 32 / / 5 48 8192 170 32 31.52% 16 / / 6 64 8192 128 0 23.44% 64 / / 7 80 8192 102 32 19.07% 16 / / 8 96 8192 85 32 15.95% 32 / / 9 112 8192 73 16 13.56% 16 / / 10 128 8192 64 0 11.72% 128 / / 11 144 8192 56 128 11.82% 16 / / 12 160 8192 51 32 9.73% 32 / / 13 176 8192 46 96 9.59% 16 / / 14 192 8192 42 128 9.25% 64
©2022 Wantedly, Inc. TQBO • mcache, mcentral͜ͷspanΛཧ͢Δ
©2022 Wantedly, Inc. TQBO • GoΦϒδΣΫτspanʹׂΓͯΒΕΔ
©2022 Wantedly, Inc. • ϝϞϦ͕ඞཁʹͳͬͨΒ͜ͷਤͷྲྀΕͰׂ͕ߦΘΕΔ 1. mcacheʹ͋Δspanʹۭ͖͕͋ΔͳΒͦ͜Λ͏ 2. mcentral͔ΒspanΛͬͯ͏ 3.
OS͔ΒϝϞϦΛଟΊʹͬͯspanʹׂͯ͠͏ TQBO౿·ׂ͑ͨ
©2021 Wantedly, Inc. ·ͱΊ
©2022 Wantedly, Inc. • Ξϩέʔλʔ • ༻ՄೳͳώʔϓϝϞϦͷཧΛߦ͏ • ߴͰஅยԽ͕ى͜ΓͮΒ͍Ξϩέʔλʔ͕ྑ͍ GoΞϩέʔλʔ
• εϨου͝ͱʹΩϟογϡΛઃ͚ͯCPUʹରͯ͠εέʔϧ͢ΔΑ͏ʹͳ͍ͬͯΔ • OS͔Βऔಘͨ͠ϝϞϦΛϒϩοΫʹ͚ͯߴͳׂΛ࣮ݱ͍ͯ͠Δ ·ͱΊ