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
Transcript
22 slides
©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͔Βऔಘͨ͠ϝϞϦΛϒϩοΫʹ͚ͯߴͳׂΛ࣮ݱ͍ͯ͠Δ ·ͱΊ
More Decks by nasa
See All by nasa
難解な自己紹介プログラムを書く
nasa_desu
1
420
鉄は熱いうちに打て - Kaigi Effect LT大会
nasa_desu
2
630
リンカを変えてgo buildを 速く出来るか
nasa_desu
2
4.1k
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
81天的 AI Agent 軟體開發團隊治理實務分享
regionbbs
0
150
AI時代における医療情報システムのセキュリティ / Security of Healthcare IT Systems in the AI Era
henryofficial
0
150
ライフワーク「猫でもわかるDirectConnect」
kentapapa
0
320
自治体AIコンタクトセンター、何をどこに任せる?~Amazon Connect Customer +Amazon Bedrockの実践知~ / 20261107 Satoshi Torano
shift_evolve
PRO
1
130
レガシーコードに対する loop engineering的なAI開発プロセス導入について
kubell_hr
0
340
Kiro IDE 入門 (画面の各部から、頼み方、任せ方、戻し方まで) | 目指せ Kiro マスター 02
inariku
PRO
4
210
An Introduction to Context Ontology Accelerator (teaching AI agents what your data means)
inariku
PRO
1
210
Claude Codeで新規事業を伸ばせるか? Zennの試行錯誤の記録
wadayusuke
1
110
続・ソフトウェアアーキテクトのための意思決定術: Decision Readiness, Revisited — When AI Changes the Economics of Software Architecture
snoozer05
PRO
9
2.9k
AWS基盤改善を支える 私たちの理念と行動指針
kentosuzuki
0
150
高品質と高スピードを支える品質のシフトレフトのアプローチ
goyoki
0
270
Kiro 入門 (1 つのエージェントを、どの画面からでも) | 目指せ Kiro マスター 01
inariku
PRO
6
1.6k
Featured
See All Featured
4 Signs Your Business is Dying
shpigford
187
23k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.7k
Crafting Experiences
bethany
1
430
Ethics towards AI in product and experience design
skipperchong
2
460
Building Flexible Design Systems
yeseniaperezcruz
330
41k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.6k
What does AI have to do with Human Rights?
axbom
PRO
1
2.5k
Design in an AI World
tapps
1
390
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
940
Product Roadmaps are Hard
iamctodd
55
13k
Amusing Abliteration
ianozsvald
1
390
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1.1k