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
【golang】構造体のフィールド宣言順序は パフォーマンスにどう影響するか?
Search
Kazuya Umeki
August 27, 2026
Technology
3
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
【golang】構造体のフィールド宣言順序は パフォーマンスにどう影響するか?
Kazuya Umeki
August 27, 2026
More Decks by Kazuya Umeki
See All by Kazuya Umeki
UI実装者が書いたシナリオだからこそ、 意味を持つk6負荷試験
umekikazuya
0
22
厚いFW・ORMの誘惑と技術選定のリアル
umekikazuya
0
3
フレームワークの「恩恵」と「制約」を見極めたバッチ処理の高速化
umekikazuya
0
11
計算量考えてます?
umekikazuya
0
17
Other Decks in Technology
See All in Technology
オントロジーって 結局なにもの? AI エージェントに「意味」を渡す知識設計の話
greenmidori
0
230
触りたくないデータに、どう触るか AI時代のRBACアクセスガバナンス
ivry_presentationmaterials
0
280
Gemini Intelligence 入門 ― AppFunctions と Gemini Nano
takuroabe
0
300
自作バイナリを動かす「入口」8選
puhitaku
2
1.3k
スプシの手作業からの解脱 ~更新はClaude Codeに、見せ方と使い方はGASアプリに任せる~
kentarofujii
0
160
フロントエンドカンファレンス関西2026 - 速すぎるUIに、待ち時間を
teamlab
PRO
0
190
トークン化預金DCJPYの取り組みと活用ユースケース
finengine
0
170
20261017福岡devIO 「AIは"良いダッシュボード"を作れるか?
jtakeda
0
190
価値について
gree_tech
PRO
0
110
AI × アーキテクト 第1・2章|生成AIの課題とアーキテクトの素養
daidaidai
0
180
データエンジニアの次の戦場は "プロセスエンジニアリング"
sansantech
PRO
1
110
パスキーの自動テストはどこまでいけるのか
teamlab
PRO
0
280
Featured
See All Featured
Building Flexible Design Systems
yeseniaperezcruz
330
41k
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.6k
Designing for humans not robots
tammielis
254
26k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.2k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3k
Into the Great Unknown - MozCon
thekraken
41
2.8k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
1
570
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
300
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
2
330
A designer walks into a library…
pauljervisheath
211
25k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
580
Believing is Seeing
oripsolob
1
250
Transcript
構造体のフィールド宣言順序は パフォーマンスにどう影響するか? 梅木和弥 Go Connect #16
前提: Go はフィールドを自動で並び替えません Rust コンパイラがフィールドを自動で並び替える Go 宣言順序はがそのままメモリレイアウトに反映される
64 bit アーキテクチャのアライメント規則 型 bool / int8 / byte int16
int32 / float23 int64 / float64 / pointer string slice サイズ 1B 2B 4B 8B 16 B 24 B アライメント 1 2 4 8 8 8
検証の目的 「フィールド宣言順序の違い」が パフォーマンスにどの程度の影響を与えるのか...。
検証方法 静的サイズ検証 それぞれのサンプルの実際のメモリレイアウトを出力。 BenchmarkAlloc 100万件のスライスを make する速度を計測。(アロケーション性能) BenchmarkTraverse 100万件を全走査して集計する速度を計測。(キャッシュライン効率) Company
Name
検証方法 サンプルA アライメントに配慮しないフィールド順序 type SampleA struct { a bool //
1 B + 7 B padding b int64 // 8 B c bool // 1 B + 3 B padding d int32 // 4 B } サンプルB サイズ降順に配置 type SampleB struct { b int64 // 8 B d int32 // 4 B a bool // 1 B c bool // 1 B + 2 B padding } Company Name
仮説 Metric SampleA SampleB Diff サイズ 24 B 16 B
-33 % Allocs/op 同等 同等 ns/op 高い 低い 改善見込みあり?
計測してきました。 Company Name
結果 ~ 静的サイズ検証 宣言順序を変更しただけで 24 B → 16 B SampleA
a b 8B d 16B SampleB b c 24 B d ac 16 B 8B 33.3 % のサイズ削減(パディングとして無駄になっていた8Bを回収) Company Name
結果 ~ ベンチマーク結果 Metric SampleA SampleB Diff Sizeof 24 B
16 B -33.3% Alloc B/op (1M) 25,165,841 16,777,232 -33.3% Alloc ns/op (1M) -353,284 -258,446 -26.8% Traverse ns/op (1M) -724,043 -638,430 -11.8% Allocs/op 1 1 0% Company Name
結論 構造体サイズが減る: -33% 大量生成時の処理速度が向上する: -27% スライス走査も高速化: -12% Company Name
ご清聴ありがとうございました。 @umekikazuya
結果 ~ ベンチマーク結果 サイズ差 -33% フィールド間パディングが計 8B 削減された ( unsafe.Sizeof
で確認) アロケーションコスト -26.8% 総バイト数が 33% 減った分に比例して make の所要時間も短縮 走査スループット -11.8% 1キャッシュライン(64B)に載る要素数が2.67個→4個に増え、キャッシュ率が低下 Allocs/op は同等 make([]T, N) は型サイズに関係なく1回の alloc。構造体サイズは回数ではなくバイト量にのみ影響。 Company Name