$30 off During Our Annual Pro Sale. View Details »
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
570
Online Nonstationary and Nonlinear Bandits with Recursive Weighted Gaussian Process
monochromegane
0
310
AIを前提とした体験の実現に向けて/toward_ai_based_experiences
monochromegane
1
660
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
850
迅速な学習機構を用いて逐次適応性を損なうことなく非線形性を扱う文脈付き多腕バンディット手法/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
WebAssembly Unleashed: Powering Server-Side Applications
chrisft25
0
2.1k
Jakarta EE meets AI
ivargrimstad
0
980
The Efficiency Paradox and How to Save Yourself and the World
hollycummins
1
250
As an Engineers, let's build the CRM system via LINE Official Account 2.0
clonn
1
650
Recoilを剥がしている話
kirik
4
5.3k
Thoughts and experiences on Rust and TypeScript
unvalley
2
220
かんたんデザイン編集やってみた~「完全に理解した」までの道のり~
morit4ryo
1
120
macOS なしで iOS アプリを開発する(※ただし xxx に限る)
mitsuharu
1
170
rails stats で紐解く ANDPAD のイマを支える技術たち
andpad
1
220
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
1
140
PipeCDの歩き方
kuro_kurorrr
4
140
[JAWS-UG横浜 #76] イケてるアップデートを宇宙いち早く紹介するよ!
maroon1st
0
370
Featured
See All Featured
Statistics for Hackers
jakevdp
796
220k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.3k
Designing Experiences People Love
moore
138
23k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
How to Ace a Technical Interview
jacobian
276
23k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
Making the Leap to Tech Lead
cromwellryan
133
9k
Code Reviewing Like a Champion
maltzj
520
39k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
32
2.7k
Optimising Largest Contentful Paint
csswizardry
33
3k
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