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 1.27 における memory allocation の高速化
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
ANDPAD inc
August 06, 2026
Programming
430
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Go 1.27 における memory allocation の高速化
unagam
X:
unagam
2026 年 8 月 5 日
golang.tokyo #44
ANDPAD inc
August 06, 2026
More Decks by ANDPAD inc
See All by ANDPAD inc
R8 の設定見直しでアプリサイズ削減
andpad
0
190
Go 探無比ワークショップ開催レポート
andpad
0
84
self-service-infrastructure-with-argocd-and-atlantis
andpad
0
12
実行場所を意識させない i18n API を作った話
andpad
1
240
言語を使う側から、作る側へ。 自作 Lisp で得た新たな気づき。
andpad
0
220
OS アップデート対応の取り組み方がもっと共有されてほしい
andpad
0
150
Vue × Nuxt × Oxc どこまで使える?実運用の現在地
andpad
0
610
ANDPAD Ruby sponsor session in RubyKaigi 2026
andpad
0
300
AWS WAFの運用を地道に改善し、自社で運用可能にするプラクティス
andpad
2
1.4k
Other Decks in Programming
See All in Programming
Everything will be SERVERLESS — 信じて運用した10年の経験値 / Everything Will be Serverless — Lessons Learned from 10 Years of Operational Experience
seike460
PRO
1
780
KiroのSpecで「五目並べ」を作ってみる
satoshi256kbyte
1
360
dotNET_vulnclicker_intro.pdf
deka_morita
0
110
AIに “答え“を書かせるのを やめてみた
___akari11
0
110
Embedded Swiftで作る自作USBデバイス によるiOSデバイスの自動テスト / iOSDC Japan 2026 glassfiber
glassfiber
0
310
ハーネス設計入門 〜 基礎知識の整理から実務へのステップアップ 〜
kinopeee
21
21k
難しいけど、読めた。- OSSの入口に立った話。
sts11142
0
140
モデルのリファクタリングが難しいと思ったら、そもそも複雑だったのはビジネス仕様だった ? / is-the-business-domain-the-real-complexity
hatsu38
0
450
Agentic Software Factoryに、すごく賢いIF文を。 / super smart IF statement into the Agentic Software Factory.
rkaga
8
1.9k
SREの越境 / SRE Collaboration
y0hgi
2
300
IBM Bob Dojo #1 仕様駆動開発入門
oniak3ibm
PRO
0
350
JRuby: Past, Present, and Future
headius
0
220
Featured
See All Featured
Bootstrapping a Software Product
garrettdimon
PRO
306
120k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
1k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.6k
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
790
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
450
Writing Fast Ruby
sferik
630
63k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.4k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
12k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
710
The Invisible Side of Design
smashingmag
301
52k
Building Adaptive Systems
keathley
44
3.2k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
390
Transcript
Go 1.27におけるmemory allocationの高速化 © 2026 ANDPAD All Rights Reserved. Confidential
1
Speaker unagam ANDPAD SWE & Science Tokyo(M2) Goとボカロが好き © 2026
ANDPAD All Rights Reserved. Confidential 2
Go 1.27 メモリへの割り当てが速くなった! ヒープへの小さい割り当て(<=80B)が最大30%高速化した プログラム全体でみると約1%高速化した 代わりにバイナリサイズが60KB増えた © 2026 ANDPAD All
Rights Reserved. Confidential 3
なぜ速くなったのかわからない The compiler now generates calls to size-specialized memory allocation
routines, … (訳: コンパイラがサイズ特化のメモリアロケーションルーチンを呼び出し、...) リリースノートより引用:https://go.dev/doc/go1.27#faster-memory-allocation 初見だと全然わからない わかりやすく解説してみよう! © 2026 ANDPAD All Rights Reserved. Confidential 4
事前知識①: ヒープ メモリ内に値を保存する領域は2種類: スタック&ヒープ スタック ヒープ 寿命 定義された関数内のみ 定義された関数が終了しても残る コスト
小さい 大きい 具体例 © 2026 ANDPAD All Rights Reserved. Confidential 5
事前知識①: ヒープ これ以降全部この話 スタック ヒープ 寿命 定義された関数内のみ 定義された関数が終了しても残る コスト 小さい
大きい 具体例 © 2026 ANDPAD All Rights Reserved. Confidential 6
事前知識②: 値(~32KB)は種類に応じて格納 1. ランタイムでサイズを事前設定(8B, 16B, 24B, 32B,…, 32KB ) 2.
値のサイズを切り上げ(22B→24B, 25B→32B) 3. 値のポインタ有無をチェック(ポインタあり/ポインタなし) 4. 該当のメモリ領域に格納 16B/ポインタあり 16B/ポインタなし 参考: https://internals-for-interns.com/posts/go-memory-allocator/ © 2026 ANDPAD All Rights Reserved. Confidential 7
従来のメモリ格納前の判別作業 メモリ格納時分類が必要になる 値のサイズは? ポインタは? 判別作業によるコストが発生していた The Go gopher was designed
by Renée French. © 2026 ANDPAD All Rights Reserved. Confidential 8
コンパイル時に大体判別可能 8B 16B(ポインタ含む) 8B 32B/ポインタありの区画に格納する © 2026 ANDPAD All Rights
Reserved. Confidential 9
コンパイル時点で判別しよう! コンパイル時点で格納先決定可能なものは決めてしまう 従来 1. サイズを事前設定する 2. 値のサイズを切り上げる 3. 値のポインタ有無をチェック 4.
該当の区画に格納する © 2026 ANDPAD All Rights Reserved. Confidential 10
コンパイル時点で判別しよう! コンパイル時点で格納先決定可能なものは決めてしまう 従来 1. サイズを事前設定 2. 値のサイズを切り上げ 3. 値のポインタ有無をチェック 4.
該当の区画に格納 Go 1.27 小さい値はコンパイラが 2~3を担当する 実行時値を格納だけでOK 判別の作業を省くことで高速化を実現した © 2026 ANDPAD All Rights Reserved. Confidential 11
実際にコンパイルして確かめる サンプルコードのmain.go Userを呼び出してNameを 表示させるだけ サンプルコードなどはこちら https://github.com/UnagamiKanta/go-1-27-faster-malloc © 2026 ANDPAD All
Rights Reserved. Confidential 12
従来のコンパイル時の呼び出し 実行するコマンド 従来の実装でビルドしてアセンブリを出力 アセンブリからメモリ割り当てだけを表示する 全ての値共通の割り当て関数が呼ばれる © 2026 ANDPAD All Rights
Reserved. Confidential 13
Go 1.27のコンパイル時の呼び出し 実行するコマンド Go1.27のメモリ割り当てを有効化する 従来 共通関数を呼び出す Go 1.27 Scan=ポインタを含む SC4
=32Bのサイズを持つ コンパイル時点でサイズ特化関数を呼び出す © 2026 ANDPAD All Rights Reserved. Confidential 14
なぜ80B以下だけなのか? 80Bより大きくても同じ手順だから同様に高速化できそう しかし実際には80Bより大きいと今回の実装から外れる https://cs.opensource.google/go/go/+/refs/tags/g o1.27rc1:src/runtime/_mkmalloc/constants.go;l=30 実際最初は512Bまで同様の実装 runtime: add specialized malloc
functions for sizes up to 512 bytes (訳: 最大512Bのサイズ特化メモリ割り当て関数を追加) https://go-review.googlesource.com/c/go/+/665835 なぜ512Bから80Bまで減らされたのか? © 2026 ANDPAD All Rights Reserved. Confidential 15
メリットよりデメリットが大きくなるから 512Bに設定後、サイズ特化関数のベンチが追加された https://go-review.googlesource.com/c/go/+/775980 ベンチが追加されてすぐ、512B→128Bに減らされた https://go-review.googlesource.com/c/go/+/776740 サイズが大きいと効果が非常に小さい CPUキャッシュ圧迫によるアプリ全体への悪影響 ベンチマーク結果をもとにサイズを変更したはず 妥協点として最終的に80Bに調整された ©
2026 ANDPAD All Rights Reserved. Confidential 16
まとめ • 小さい値のヒープ割り当てが速くなった • 割り当て区画の判別にコストが発生していた • 判別をコンパイラ側で行うようにした • 80Bになったのはメリットとデメリットの妥協点のため ©
2026 ANDPAD All Rights Reserved. Confidential 17
宣伝:このベンチマーク結果を見つけよう! GoConで弊社エンジニアがワークショップを開催します! https://gocon.jp/2026/news/session-announcement/ 今回のベンチ結果含め多くのワークを用意しています! © 2026 ANDPAD All Rights Reserved.
Confidential 18
We are hiring !! Mission 幸せを築く人を、幸せに。 エンジニア採用ページ 住まいをつくる。ビルや施設をつくる。街をつくる。 生活を豊かにする建築・建設業は、幸せづくりと例えられます。 私たちは、その幸せづくりをする人たちをテクノロジーの力で
カジュアル面談 後押ししていきたい。心からそう考えてます。 応募フォーム 我々はこれからもお客様の声をサービスに反映して、 建設業界及び建設業従事者様の業務効率化、 DX化を支援してまいります。 開発部公式 X アカウント @andpad_dev Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. 無断転載・無断複製の禁止 Confidential