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
8
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
【golang】構造体のフィールド宣言順序は パフォーマンスにどう影響するか?
Kazuya Umeki
August 27, 2026
Transcript
13 slides
構造体のフィールド宣言順序は パフォーマンスにどう影響するか? 梅木和弥 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
More Decks by Kazuya Umeki
See All by Kazuya Umeki
UI実装者が書いたシナリオだからこそ、 意味を持つk6負荷試験
umekikazuya
0
28
厚いFW・ORMの誘惑と技術選定のリアル
umekikazuya
0
10
フレームワークの「恩恵」と「制約」を見極めたバッチ処理の高速化
umekikazuya
0
27
"当たり前"を疑いましょ ~フレームワークからドメインを守るDrupalアーキテクチャ~
umekikazuya
0
3
計算量考えてます?
umekikazuya
0
18
Other Decks in Technology
See All in Technology
AWS Client VPNの設定でハマったポイントとその過程での気づき
amarelo_n24
1
400
ぼくのClaude Codeの使い方
falken
PRO
5
7.6k
コピーオンライト型ファイルシステムと ランダム書き込み
sat
PRO
2
130
会社説明資料_最新版
demaecan
0
32k
アラートを見直していたら営業組織への理解にちょっとだけ繋がった話
z63d
1
210
Amazon Bedrock AgentCore の基礎とセキュリティ・ガバナンス
ren8k
0
160
PHPで家庭用ゲーム機の専用コントローラーをMIDIデバイスとして扱ってみる
wind111
0
160
Linuxネットワークスタック進化の軌跡: 過去10年の歩みと最新トレンド
orimanabu
4
760
E2E Test というハーネス — AI時代の自動テスト民主化
daishukojima
10
5.8k
マネージャーをエスパーにしない マネジメントされる側から始める、働きやすい現場づくり
comi190327
1
790
エンタープライズIAMについて - ID・権限をどう統制するか
oidfj
1
210
[NW-JAWS DAY]「うちのAWS、インターネット出られないんで」― AWS外の自社サービスをPrivateLinkでシュッと公開する方法
ykimi
3
880
Featured
See All Featured
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
380
The Pragmatic Product Professional
lauravandoore
37
7.5k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
750
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.2k
VelocityConf: Rendering Performance Case Studies
addyosmani
331
25k
How to Ace a Technical Interview
jacobian
280
24k
Code Reviewing Like a Champion
maltzj
529
40k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
540
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
760
Accessibility Awareness
sabderemane
1
310
Designing Powerful Visuals for Engaging Learning
tmiket
1
660