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
500
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
150
多様かつ継続的に変化する環境に適応する情報システム/thesis-defense-presentation
monochromegane
1
530
Online Nonstationary and Nonlinear Bandits with Recursive Weighted Gaussian Process
monochromegane
0
280
AIを前提とした体験の実現に向けて/toward_ai_based_experiences
monochromegane
1
640
Go言語でMac GPUプログラミング
monochromegane
1
390
Contextual and Nonstationary Multi-armed Bandits Using the Linear Gaussian State Space Model for the Meta-Recommender System
monochromegane
1
840
迅速な学習機構を用いて逐次適応性を損なうことなく非線形性を扱う文脈付き多腕バンディット手法/extreme_neural_linear_bandits
monochromegane
0
1.9k
再帰化への認知的転回/the-turn-to-recursive-system
monochromegane
0
720
仮想的な探索を用いて文脈や時間の経過による番狂わせにも迅速に追従する多腕バンディット手法/wi2_lkf_bandits
monochromegane
0
660
Other Decks in Programming
See All in Programming
Jakarta EE meets AI
ivargrimstad
0
510
WebフロントエンドにおけるGraphQL(あるいはバックエンドのAPI)との向き合い方 / #241106_plk_frontend
izumin5210
4
1.4k
Duckdb-Wasmでローカルダッシュボードを作ってみた
nkforwork
0
120
聞き手から登壇者へ: RubyKaigi2024 LTでの初挑戦が 教えてくれた、可能性の星
mikik0
1
120
Webの技術スタックで マルチプラットフォームアプリ開発を可能にするElixirDesktopの紹介
thehaigo
2
1k
Laravel や Symfony で手っ取り早く OpenAPI のドキュメントを作成する
azuki
1
110
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
470
as(型アサーション)を書く前にできること
marokanatani
9
2.6k
Content Security Policy入門 セキュリティ設定と 違反レポートのはじめ方 / Introduction to Content Security Policy Getting Started with Security Configuration and Violation Reporting
uskey512
1
520
OnlineTestConf: Test Automation Friend or Foe
maaretp
0
100
イベント駆動で成長して委員会
happymana
1
320
Amazon Qを使ってIaCを触ろう!
maruto
0
400
Featured
See All Featured
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Designing on Purpose - Digital PM Summit 2013
jponch
115
7k
Unsuck your backbone
ammeep
668
57k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Music & Morning Musume
bryan
46
6.2k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Being A Developer After 40
akosma
86
590k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
For a Future-Friendly Web
brad_frost
175
9.4k
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