Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
dragon-importsで爆速goimports生活 - プロジェクト Go module...
Search
monochromegane
February 12, 2019
Programming
1
510
dragon-importsで爆速goimports生活 - プロジェクト Go modules -/dragon-imports
Fukuoka.go#13+Okayama.go #fukuokago
https://fukuokago.connpass.com/event/112073/
monochromegane
February 12, 2019
Tweet
Share
More Decks by monochromegane
See All by monochromegane
Go言語でターミナルフレンドリーなAIコマンド、afaを作った/fukuokago20_afa
monochromegane
2
170
多様かつ継続的に変化する環境に適応する情報システム/thesis-defense-presentation
monochromegane
1
590
Online Nonstationary and Nonlinear Bandits with Recursive Weighted Gaussian Process
monochromegane
0
330
AIを前提とした体験の実現に向けて/toward_ai_based_experiences
monochromegane
1
680
Go言語でMac GPUプログラミング
monochromegane
1
430
Contextual and Nonstationary Multi-armed Bandits Using the Linear Gaussian State Space Model for the Meta-Recommender System
monochromegane
1
860
迅速な学習機構を用いて逐次適応性を損なうことなく非線形性を扱う文脈付き多腕バンディット手法/extreme_neural_linear_bandits
monochromegane
0
2k
再帰化への認知的転回/the-turn-to-recursive-system
monochromegane
0
730
仮想的な探索を用いて文脈や時間の経過による番狂わせにも迅速に追従する多腕バンディット手法/wi2_lkf_bandits
monochromegane
0
670
Other Decks in Programming
See All in Programming
ブラウザ単体でmp4書き出すまで - muddy-web - 2024-12
yue4u
2
460
バグを見つけた?それAppleに直してもらおう!
uetyo
0
170
ソフトウェアの振る舞いに着目し 複雑な要件の開発に立ち向かう
rickyban
0
890
Scalaから始めるOpenFeature入門 / Scalaわいわい勉強会 #4
arthur1
1
300
DevFest Tokyo 2025 - Flutter のアプリアーキテクチャ現在地点
wasabeef
5
890
快速入門可觀測性
blueswen
0
310
42 best practices for Symfony, a decade later
tucksaun
1
180
フロントエンドのディレクトリ構成どうしてる? Feature-Sliced Design 導入体験談
osakatechlab
8
4.1k
The Efficiency Paradox and How to Save Yourself and the World
hollycummins
1
440
Webエンジニア主体のモバイルチームの 生産性を高く保つためにやったこと
igreenwood
0
330
layerx_20241129.pdf
kyoheig3
2
290
14 Years of iOS: Lessons and Key Points
seyfoyun
1
770
Featured
See All Featured
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
0
94
How GitHub (no longer) Works
holman
311
140k
Building an army of robots
kneath
302
44k
Practical Orchestrator
shlominoach
186
10k
The Pragmatic Product Professional
lauravandoore
32
6.3k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.3k
Designing for humans not robots
tammielis
250
25k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
[RailsConf 2023] Rails as a piece of cake
palkan
53
5k
Music & Morning Musume
bryan
46
6.2k
Building Applications with DynamoDB
mza
91
6.1k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.9k
Transcript
- ϓϩδΣΫτ Go modules - ࡾ༔հ / Pepabo R&D Institute,
GMO Pepabo, Inc. 2019.02.12 Fukuoka.go#13+Okayama.go dragon-importsͰ രgoimportsੜ׆
ϓϦϯγύϧΤϯδχΞ ࡾ༔հ!NPOPDISPNFHBOF (.0ϖύϘגࣜձࣾϖύϘݚڀॴ IUUQTCMPHNPOPDISPNFHBOFDPN
1. Motivation 2. Problem of goimports 3. Approach by dragon-imports
4. Evalution 5. Discussion about Go modules 3 ࣍
1. Motivation
͓·͑ ࠓ·ͰΠϯϙʔτͨ͠ ίʔυͷΛ ͓΅͍͑ͯΔͷ͔ʁ
• goimportsimportߦͷߋ৽ΛࣗಈͰߦͬͯ͘ΕΔͨΊඇৗʹศར • goimports։ൃதɼԿ࣮ߦ͞ΕΔ • ୳ࡧରͷύοέʔδ͕૿͑Δͱ࣮ߦ͕͘ͳΓੜ࢈ੑ͕Լ͕Δ • ಛʹghq+pecoͰϩʔΧϧϦϙδτϦΛ౷Ұཧ͍ͯ͠Δ߹ʹݦஶ • ͦ͜Ͱ୳ࡧରͷύοέʔδ͕૿࣮͑ͯߦ͕มΘΒͳ͍άϨʔτͳ
goimports͕ٻΊΒΕΔ 6 goimportsͷԽΛղܾ͍ͨ͠
2. Problem of goimports
• ରͷίʔυΛASTʹม͠importߦΛߋ৽ɼՃɼআɽͦͷޙɼϑΥʔ ϚοτࡁΈίʔυΛग़ྗ͢Δ • ୳ࡧରͷύοέʔδʹඪ४ϥΠϒϥϦͱ֎෦ύοέʔδ͕͋Δ • $GOPATH/src, $GOPATH/pkg/mod • ରͷೖྗதͷύοέʔδ໊ɼγϯϘϧ໊ͷΈ߹ΘͤΛશͯຬͨ͢Πϯϙʔ
τύεΛղܾ͢Δ • math/rand (import path), rand (package name), Int (symbol) 8 goimportsͷجຊ
9 goimportsͷ࣮ߦྫ $ cat imp.txt package imp func hoge() {
fmt.Println("hello.") kaburaya.Recorder } $ goimports imp.txt package imp import ( "fmt" "github.com/monochromegane/kaburaya" ) func hoge() { fmt.Println("hello.") kaburaya.Recorder }
• ΑΓਖ਼͘͠୳ࡧରͱͳΔʮ֎෦ʯύοέʔδ͕૿Ճͨ͠߹ʹ͘ͳΔ • ΫϥΠΞϯτڥ࣌ؒܦաʹΑͬͯ֎෦ύοέʔδҰཡมԽ͢Δ͜ͱ͔Βɼ୳ࡧ ରͷσΟϨΫτϦ୳ࡧɼߏจղੳɼϦϑΝϨϯεͷநग़Λߦ͏ඞཁ͕͋ΔͨΊɽ • ରʹɼύοέʔδҰཡ͕ڥʹΑͬͯมԽ͠ͳ͍ඪ४ύοέʔδΠϯϙʔ τύεɼύοέʔδ໊ɼγϯϘϧͷϦετΛࣄલʹղੳ͞Ε͍ͯΔ 10 ͳͥgoimports͕͘ͳΔͷ͔
goimportsඪ४ύοέʔδ 11 package imports var stdlib = map[string]map[string]bool{ "archive/tar": map[string]bool{
"ErrFieldTooLong": true, "ErrHeader": true, "ErrWriteAfterClose": true, "ErrWriteTooLong": true, $GOROOT/api/go1.*txt golang.org/x/tools/imports/mkstdlib.go golang.org/x/tools/imports/zstdlib.go golang.org/x/tools/cmd/goimports.go#main golang.org/x/tools/imports/imports.go#Process golang.org/x/tools/imports/fix.go#addStdlibCandidates pkg crypto/rsa, method (*PrivateKey) Size() int pkg crypto/rsa, method (*PublicKey) Size() int
• First pass (Πϯϙʔτ͕ඞཁ͔ௐΔ) • ରͷϦϑΝϨϯεҰཡͱimportߦ͕߹க͢Δ͔֬ೝ • Second pass (ඪ४ύοέʔδ·ͨطimportߦ͔Βղܾ)
• var stdlib·ͨଞϑΝΠϧͰimportࡁΈͷߦΛީิͱͯ͠߹க͢Δ͔֬ೝ • Third pass (֎෦ύοέʔδ͔Βղܾ) • $GOPATH/src͘͠$GOPATH/pkg/mod͔ΒϦϑΝϨϯεʹࣅͨσΟϨΫτϦΛߜΓࠐ ΈɼީิϑΝΠϧΛղੳͯ֬͠ೝ 12 goimportsͷߴԽͷ
13 ஈ֊͝ͱͷ࣮ߦ TUQBTT ЖT OEQBTT ЖT SEQBTT ЖT Πϯϙʔτෆཁ
ඪ४ϥΠϒϥϦͷΤΫεϙʔτΛࢀর ଞϑΝΠϧͷΠϯϙʔτΛࢀর ֎෦ύοέʔδͷΤΫεϙʔτΛࢀর $ tree !"" imp.txt !"" other.go #"" other2.go $ find . -type d | wc -l 120840 Original goimports
3. Approach by dragon-imports
• ΫϥΠΞϯτڥ͝ͱʹ୳ࡧରͷύοέʔδҰཡਓؒ࣌ؒͰ͔͠มԽ͠ ͳ͍ • ࣄલղੳͷ݁Ռ͕ݱঢ়ʹԊΘͳ͚Εશ୳ࡧΛߦ͏ϑΥʔϧόοΫ͕Մೳ • ͞ΒʹΠϯϙʔτߦʹޡΓ͕͋ͬͯϏϧυͰࣦഊ͢Δ • ͜ΕΒͷલఏ͔Β֤ΫϥΠΞϯτڥ͝ͱʹ୳ࡧରͷύοέʔδΛҙͷλ ΠϛϯάͰࣄલղੳ͓ͯ͘͜͠ͱͰgoimportsͷߴԽ͕Մೳ
15 ఏҊख๏ͷண؟
• monochromegane/dragon-imports • A tool for speedup go imports command
• https://github.com/monochromegane/dragon-imports • ඪ४ύοέʔδͱ$GOPATH/srcΛղੳ͠ɼzstdlib.goΛ࠶ੜɼgoimportsͷ ࠶Πϯετʔϧ·Ͱߦ͏ • zstdlib.go(=var stdlib)ͷͷߴ͞ʹΑΓैੑ൚༻ੑ͕ߴ·Δ 16 ఏҊख๏ͷ࣮ $ go get github.com/monochromegane/dragon-imports/... $ dragon-imports
dragon-imports 17 package imports var stdlib = map[string]map[string]bool{ "archive/tar": map[string]bool{
"ErrFieldTooLong": true, "ErrHeader": true, "ErrWriteAfterClose": true, "ErrWriteTooLong": true, $GOROOT/api/go1.*txt dragon-imports golang.org/x/tools/imports/zstdlib.go golang.org/x/tools/cmd/goimports.go#main golang.org/x/tools/imports/imports.go#Process golang.org/x/tools/imports/fix.go#addStdlibCandidates $GOPATH/**/*.go
4. Evalution
19 ࣮ߦ࣌ؒͷൺֱ TUQBTT ЖT OEQBTT ЖT SEQBTT ЖT Πϯϙʔτෆཁ
ඪ४ϥΠϒϥϦͷΤΫεϙʔτΛࢀর ଞϑΝΠϧͷΠϯϙʔτΛࢀর ֎෦ύοέʔδͷΤΫεϙʔτΛࢀর Original goimports TUQBTT ЖT OEQBTT ЖT SEQBTT ЖT Πϯϙʔτෆཁ ඪ४ϥΠϒϥϦͷΤΫεϙʔτΛࢀর ଞϑΝΠϧͷΠϯϙʔτΛࢀর ֎෦ύοέʔδͷΤΫεϙʔτΛࢀর Dragonize goimports
5. Discussion about Go modules
• Go modulesΛ༗ޮʹ͢Δͱ$GOPATH/srcͰͳ͘$GOPATH/pkg/modԼ ͷόʔδϣχϯάཧ͞Εͨύοέʔδ͕ར༻͞ΕΔ • goimportsͰ୳ࡧରΛಉ͡Α͏ʹΓସ͍͑ͯΔ • ֎෦ύοέʔδʹόʔδϣχϯάͷ֓೦͕ಋೖ͞ΕΔͨΊɼಉҰΠϯϙʔτύ εͰ͋ͬͯγϯϘϧϦετ͕ҟͳΔՄೳੑ͕͋Δʢͨͩ͠ϝδϟʔόʔδϣ ϯ͕ҟͳΔͱ/v2ͷΑ͏ʹผͱͯ͠ѻ͑Δʣ
• ඪ४ύοέʔδόʔδϣχϯάͷ֓೦͕·ͩͳ͍ͨΊzstdlib.goෳόʔ δϣϯͷγϯϘϧΛѻ͏ߏʹͳ͍ͬͯͳ͍ 21 Go modulesΛͲ͏ѻ͏͔
• Go modulesཧͷ֎෦ύοέʔδΛࣄલղੳ͢Δ • ΦϓγϣϯʹΑͬͯղੳରΛGOPATH/pkg/modʹมߋ͢ΔɽGO111MODULES=autoͷ ڍಈաظͰ͋Δ͜ͱɼzstdlib.goWorkingDirΛΕͳ͍͜ͱ͔ΒରԠ͠ͳ͍ • ֎෦ύοέʔδ֤ϝδϟʔόʔδϣϯͷ࠷৽ͷΈΛࣄલղੳ͢Δ • ϚΠφʔόʔδϣϯҎԼͷෳόʔδϣϯ͕ଘࡏ͢Δ߹ɼbreaking
changeͳ͍લఏͰ ඪ४ύοέʔδͱಉ༷ʹ࠷৽ͷΈରԠɽsemverະରԠͳ֎෦ύοέʔδʹ͓͍ͯຊํ ʹΑͬͯޡఆࢭɼ࠷৽Խͷಈػ͚ͱ͢Δ • vendoringࣄલղੳ͠ͳ͍ • ͦͦڞ௨Խ͞Εͨύοέʔδ܈͕૿େ͢Δ͜ͱͰҾ͖ى͜͞ΕΔԆͰ͋ΓɼϓϩδΣ Ϋτ͝ͱͷ࠷খͷύοέʔδ୳ࡧʹΑΔԆߟ͑ʹ͍ͨ͘Ί 22 Go modulesΛͲ͏ѻ͏͔
23 dragon-imports $ go get -u github.com/monochromegane/dragon-imports/... $ dragon-imports --gomodules
• gomodulesΦϓγϣϯΛ࣮ݧతʹఏڙ • Go1.12ͷਖ਼ࣜαϙʔτͷঢ়گΛݟͯΦϓγϣϯॳظΛtrueͱ͢Δ༧ఆ • ܅ࠓ͙͢go get -u !!!
• Go modulesͰv2Ҏ߱ͷϝδϟʔόʔδϣϯ͝ͱʹΠϯϙʔτύε͕ҟͳΔ • ͔͠͠ύοέʔδύεϝδϟʔόʔδϣϯΛؚ·ͳ͍ 24 v2ͱ͍͏٬ $ tree !""
hellomod $ #""
[email protected]
#""
[email protected]
package main import "github.com/donvito/hellomod/v2" func main() { hellomod.SayHello("Melvin") } • ඪ४ϥΠϒϥϦόʔδϣϯΛߟྀ͠ͳ͍ͨΊ “v2”ͱ“hellomod”Λൺֱ͞Ε ͯ͠·͍ɼ֎෦ύοέʔδ୳ࡧ͕࢝·ͬͯ͠·͏……………………………!!!
R.I.P.
• dragon-importsͷΈΛհͨ͠ • UsefulͳΕͲGo modules࣌ʹશରԠݫͦ͠͏ • ७ਮʹύοέʔδ͚ͩͷσΟϨΫτϦͱͳΔͷͰԆൃੜ͠ͳ͍ͱࢥΘΕ Δɽ͠Β͘ӡ༻ͯ͠ࠔͬͨΒdragon-import.v2Λߟ͑Δɽ • Go
modules࣌ͷศརπʔϧ࡞͍ͬͯ͜͏ • ͱΓ͋͑ͣGo modulesʹدͤΔʹͨͬͯҰཡΛऔಘ͢ΔͨΊͷ ’mole(ཽ)’Λ࡞ͬͯΔ https://github.com/monochromegane/mole 26 ·ͱΊ
None