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
840
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
410
鉄は熱いうちに打て - Kaigi Effect LT大会
nasa_desu
2
610
リンカを変えてgo buildを 速く出来るか
nasa_desu
2
4k
RustでOS開発はじめの一歩
nasa_desu
8
7.6k
ログから学ぶgo build
nasa_desu
4
1.6k
GoとRust - 並行処理編
nasa_desu
5
4.2k
Other Decks in Technology
See All in Technology
全員がプロダクトへ向き合う組織を持続成長させるために——組織づくりのフライホイールと4象限 / The Flywheel Model and Four Quadrants for Organizational Design
hiro_torii
4
960
KPIだけでは評価できないプロダクトが考えるべき Evalsという第二の評価系 / Beyond KPIs: Evals as a Second Evaluation Framework for Products #PdEConf
aki_iinuma
4
3.9k
あるけみー式LTスライド作成術
alchemy1115
1
170
10分で知る最近のOmarchy
komagata
0
240
アプリをもっと"iOSアプリっぽく"する小さな工夫 / Small Touches That Make Your App Feel More Like an iOS App
matsuji
1
430
ペアプロの価値はコードを書くことだけじゃない
codmoninc
PRO
0
160
enechainの内製セルフサービスプラットフォーム
hiyosi
0
150
[2026-09-11]SREは誰のもの?運用エンジニアが始める 「SRE領域への越境」とチームの進化の軌跡 〜Road to NEXT CRE
tosite
0
120
多層防御と最⼩権限で実現する、安全なAIエージェント設計パターン
lycorptech_jp
PRO
1
250
Multica × 長期記憶:40個のミニプロジェクト管理
eiei114
1
230
2026-09-09 【sigma_ucj#1】Sigma を IaC 管理したい! / IaC for Sigma
civitaspo
0
110
Snowflakeで実現する全社横断の顧客の声(VOC)分析・活用基盤@Snowflake World Tour Tokyo 2026
yuto16
0
160
Featured
See All Featured
Odyssey Design
rkendrick25
PRO
2
800
The Limits of Empathy - UXLibs8
cassininazir
1
650
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Designing Experiences People Love
moore
143
24k
[RailsConf 2023] Rails as a piece of cake
palkan
59
7k
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
590
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.6k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
410
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
730
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
230
Rebuilding a faster, lazier Slack
samanthasiow
85
9.6k
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͔Βऔಘͨ͠ϝϞϦΛϒϩοΫʹ͚ͯߴͳׂΛ࣮ݱ͍ͯ͠Δ ·ͱΊ