- इस रिलीज़ में generic methods पर केंद्रित होकर struct literal और type inference को बेहतर बनाया गया है, और standard library, runtime और toolchain भर में व्यावहारिक फीचर जोड़े गए हैं
- size-specialized memory allocation के ज़रिए 80 byte से छोटे कुछ allocations की लागत अधिकतम 30% तक घटती है, और allocation-heavy प्रोग्रामों में लगभग 1% performance सुधार तथा लगभग 60KB binary वृद्धि की उम्मीद है
encoding/json/v2अब आधिकारिक रूप से उपलब्ध है और मौजूदाencoding/jsonभी अंदरूनी तौर पर v2 का उपयोग करता है; standard UUID package और FIPS 204 आधारित ML-DSA signatures भी जोड़े गए हैंgoroutineleakprofile, traceback में pprof labels, virtual time के लिएsynctest.Sleep, और in-memory HTTP test server की वजह से diagnostics और concurrency testing आसान हो जाती है- timer channels का unbuffered होना, HTTP response body का automatic draining, और
//go:linknamerestrictions का कड़ा होना मौजूदा code को प्रभावित कर सकता है, इसलिए Go 1.27 में जाने से पहले compatibility check ज़रूरी है
भाषा और type system
- Go 1.27 की मुख्य विशेषता generic methods है, जो receiver से स्वतंत्र अपने type parameters घोषित कर सकती हैं
- पहले केवल top-level functions ही generic हो सकती थीं, इसलिए किसी type से जुड़ी operations भी package functions के रूप में लिखनी पड़ती थीं
Box[T].Map[U]की तरह input से अलग element type लौटाने वाली operation को method के रूप में परिभाषित किया जा सकता है- interfaces अब भी type-parameter methods घोषित नहीं कर सकतीं, और generic methods के ज़रिए interface implement भी नहीं किया जा सकता
- struct literal keys में अब केवल top-level field name ही नहीं, बल्कि वैध field selectors भी इस्तेमाल किए जा सकते हैं
- embedded structs के promoted fields को
User{ID: 7}की तरह सीधे initialize किया जा सकता है
- embedded structs के promoted fields को
- function type inference को conversion और composite literals तक बढ़ाया गया है
[]func([]int) int{first, last}की तरह expected function type के आधार पर generic function के type arguments infer किए जाते हैं- पहले
first[int],last[int]की तरह सीधे instantiate करना पड़ता था
runtime और performance
- compiler अब size-specialized allocation routines को call करता है, जिससे 80 byte से छोटे कुछ memory allocations की लागत अधिकतम 30% तक घटती है
- वास्तविक allocation-heavy प्रोग्रामों में कुल performance सुधार लगभग 1% रहने की उम्मीद है
- code बदलने की ज़रूरत नहीं है, लेकिन workload से अलग लगभग 60KB binary size बढ़ती है
- इसे
GOEXPERIMENT=nosizespecializedmallocसे बंद किया जा सकता है, लेकिन यह विकल्प Go 1.28 में हटाया जाएगा
- डिफ़ॉल्ट रूप से enabled compiler optimizations की तीन नई श्रेणियाँ जोड़ी गई हैं
- known bits data-flow pass, जो उन bits को ट्रैक करता है जिनका मान निश्चित रूप से 0 या 1 है और redundant operations हटाता है
- loop-invariant code motion, जो loop के दौरान न बदलने वाली computations को loop के बाहर ले जाता है
- शर्तें मिलने पर
switchकोfallthroughसहित lookup table के रूप में compile किया जाता है
- experimental
GOEXPERIMENT=mapsplitgroupmap group की memory layout कोKVKVKVKVसेKKKKVVVVमें बदलता है, और यह डिफ़ॉल्ट रूप से बंद है - linker type descriptors और itab को dedicated
.go.typesection में ले जाता है औरtypelinksवitablinksको हटा देता हैreflect.typelinksअब offsets की जगह types लौटाता है, इसलिए//go:linknameसे इस symbol को access करने वाली libraries प्रभावित हो सकती हैं
goroutine diagnostics और profiling
- जिन modules के
go.modमें Go 1.27 या उससे ऊपर है, वे traceback के goroutine header मेंruntime/pproflabels दिखाते हैंpprof.Doसे जोड़ा गया{request: 42}जैसा context crash dump,SIGQUIT, औरruntime.Stackoutput में दिखाई देगा- traceback में sensitive labels उजागर न हों, इसके लिए
GODEBUG=tracebacklabels=0का उपयोग जारी रखा जा सकता है
- Go 1.26 का experimental goroutine leak detector अब आधिकारिक
goroutineleakprofile बन गया है- यह GC चलाकर channel या mutex आदि पर हमेशा के लिए अटकी goroutines ढूँढता है और उनका stack output करता है
- services में इसे
/debug/pprof/goroutineleakendpoint से collect किया जा सकता है औरGOEXPERIMENTकी ज़रूरत नहीं है
cryptography और identifiers
- नया crypto/mldsa package FIPS 204 की post-quantum signature ML-DSA को implement करता है
MLDSA44,MLDSA65,MLDSA87तीन parameter sets key/signature size और security level के बीच संतुलन बनाते हैंcrypto/x509की keys/signatures औरcrypto/tlsकी TLS 1.3 signature schemes में भी ML-DSA जोड़ा गया है
- standard library का नया uuid package RFC 9562 UUID को cryptographically secure random numbers से generate और parse करता है
uuid.New()सामान्य उपयोग के लिए उपयुक्त तरीका चुनता है, जबकिNewV4()शुद्ध random UUID औरNewV7()creation-time ordered UUID बनाता है- random-component UUID comparable होते हैं, इसलिए सीधे
==इस्तेमाल किया जा सकता है - समयक्रम में sort होने वाला UUID v7 database keys के लिए उपयुक्त है
JSON और data processing API
- encoding/json/v2 और low-level
encoding/json/jsontextअबGOEXPERIMENT=jsonv2के बिना उपलब्ध हैं- मौजूदा
encoding/jsonv1 भी अंदरूनी रूप से v2 implementation का उपयोग करता है - कुछ error message wording को छोड़कर पुराना behavior बरकरार है, इसलिए migration की ज़रूरत नहीं है
- अगर compatibility issue हो तो
GOEXPERIMENT=nojsonv2से मूल v1 implementation बहाल की जा सकती है - v2 performance के लिए map keys को डिफ़ॉल्ट रूप से sort नहीं करता, इसलिए stable output चाहिए तो tests में
json.Deterministicदेना होगा
- मौजूदा
strings.CutLastऔरbytes.CutLastआख़िरी delimiter के आधार पर value को split करते हैं- अगर delimiter न मिले तो पूरा input, खाली trailing part, और
falseलौटाया जाता है
- अगर delimiter न मिले तो पूरा input, खाली trailing part, और
hash/maphashका genericHasher[T]value की hash और equality strategy को साथ में परिभाषित करता है- समान values का hash भी समान होना चाहिए
- comparable types के लिए
ComparableHasher[T]दिया गया है, और case-insensitive strings जैसी custom strategies भी implement की जा सकती हैं
math/big.Int.Dividequotient और remainder को साथ में compute करता है औरTrunc,Floor,Round,Ceilमें से explicit rounding mode लागू करता है- rounding mode के अनुसार remainder भी बदलता है, जिससे financial और numerical code में पुराने
QuoऔरModकी zero-toward truncation सीमा पूरी होती है
- rounding mode के अनुसार remainder भी बदलता है, जिससे financial और numerical code में पुराने
math/rand/v2.(*Rand).Nअपने*Randsource से arbitrary integer या duration type के लिए bounded random number बनाता है
portable SIMD
- experimental simd package vector-size independent SIMD API देता है और इसे
GOEXPERIMENT=simdसे enable किया जाता है- supported environments में यह वास्तविक hardware vector instructions में compile होता है, नहीं तो pure Go emulation इस्तेमाल होती है
Float32sजैसे types में lanes की संख्या fixed नहीं है, बल्कि मशीन के hardware width पर निर्भर करती है
- standard library पहले से internal
simd/archsimdintrinsics का उपयोग करती है- Swiss Table map के
MemHash32,MemHash64,StrHashको नए SIMD-आधारित रूप में फिर से implement किया गया है
- Swiss Table map के
deterministic testing
testing/synctest.Sleepvirtual time को आगे बढ़ाने और सभी goroutines के स्थिर होने तक इंतज़ार करने का काम एक साथ करता हैsynctestbubble के अंदर वास्तविक समय नहीं बीतता, इसलिए 2 सेकंड का wait भी तुरंत पूरा हो जाता है- यह पुराने
time.Sleepऔरsynctest.Waitके repeated combination code को बदल देता है
httptest.NewTestServerवास्तविक TCP port की जगह in-memory virtual network पर server चलाता हैsrv.Client()process के अंदरूनी pipe के ज़रिए सीधे handler से जुड़ता हैt.Cleanupसे automatic cleanup हो जाता है, इसलिएdefer srv.Close()की ज़रूरत नहीं हैtesting/synctestके साथ मिलाकर HTTP round-trip को भी virtual time में तेज़ और deterministic तरीके से test किया जा सकता है
network और compatibility changes
time.After,time.NewTimer,time.NewTickerआदि से लौटने वाले channels अब हमेशा synchronous unbuffered channels होंगे- पुराना buffered behavior लौटाने वाला
asynctimerchanGODEBUG setting हटा दिया गया है
- पुराना buffered behavior लौटाने वाला
- HTTP/1 में
http.Response.Body.Closeन पढ़े गए body को conservative limit तक पढ़ता है ताकि connection reuse में मदद मिल सके- अगर आप बड़े download को जल्दी रोकने के लिए
Closeपर निर्भर थे, तोTransport.DisableKeepAlivesसे reuse बंद करना होगा
- अगर आप बड़े download को जल्दी रोकने के लिए
- HTTP/2 server अब RFC 9218 client priorities को समझता है और उच्च priority streams को पहले process करता है
Server.DisableClientPriority = trueसे पुराना round-robin behavior वापस लाया जा सकता है
- Windows और macOS पर
crypto/x509.SystemCertPoolअबSSL_CERT_FILEऔरSSL_CERT_DIRको support करता है- variables set होने पर यह disk से root certificates पढ़ता है और platform API की जगह Go verifier का उपयोग करता है
GODEBUG=x509sslcertoverrideplatform=0से इसे बंद किया जा सकता है
- पहले 12,226 lines की generated file
h2_bundle.goमें शामिल HTTP/2 implementation को असलीnet/http/internal/http2package से बदल दिया गया है net/httpमें external release से पहले वाले stage के plug-in HTTP/3 hooks जोड़े गए हैं, और test suite का कुछ हिस्सा HTTP/3 पर चलाया जाता है- अभी कोई callable public API नहीं है, लेकिन भविष्य के QUIC-आधारित
http.Transportके लिए आधार शामिल है
- अभी कोई callable public API नहीं है, लेकिन भविष्य के QUIC-आधारित
toolchain
go testअबgo.modमें घोषित Go version से नए standard library symbols के उपयोग को ढूँढने वालीstdversionvet check को डिफ़ॉल्ट रूप से चलाता हैgo doc pkg@versionसे किसी खास module version की documentation देखी जा सकती हैgo doc -exexecutable examples की सूची दिखाता है, और example name सीधे देने पर source output करता हैgo fixमेंatomictypes,embedlit,slicesbackward,unsafefuncsmodernization analyzers जोड़े गए हैंwaitgroupका नाम बदलकरwaitgroupgoकिया गया है औरfmtappendfहटा दिया गया है
- Go 1.27 या उससे ऊपर के modules में
go mod tidyबिखरे हुएrequireblocks को direct और indirect dependencies के लिए दो blocks में मिलाता है और comments को सुरक्षित रखता है go tool trace -http=:6060में केवल port देने पर यह सिर्फ localhost से bind करता है; external access के लिए address explicitly देना होगाgocommand ने Bazaar(bzr) version control system का support हटा दिया हैcompile,link,asm,cgo,cover,packअब GCC-style response files (@file) को support करते हैं, जिससे command-line length limit से बचा जा सकता है
Unicode और security boundaries
- standard library का Unicode data Unicode 15 से Unicode 17 में अपडेट किया गया है
- Unicode 16 में जोड़े गए characters भी अब symbols और printable characters के रूप में सही तरह classify होते हैं
os.Root.ReadDirऔरReaddirके ज़रिए root के बाहर निकल पाने वाली समस्या को ठीक कर दिया गया है- अनधिकृत
//go:linknameउपयोग को और कठिन बना दिया गया हैlinknamestddirective उन linkname को चिह्नित करता है जिन्हें केवल standard library import कर सकती है- linker अब assembly symbols पर linkname access की भी जाँच करता है, इसलिए अनौपचारिक internal symbols पर निर्भर code को जल्दी test करना ज़रूरी है
1 टिप्पणियां
Lobste.rs की राय
शायद अब तक की सबसे बेहतरीन रिलीज़। SIMD, uuid, jsonv2 आखिरकार आ गए
यह थोड़ा विषय से हटकर है, लेकिन यह एक अच्छा उदाहरण है कि जब हर चीज़ को string की तरह ट्रीट किया जाए और interface methods के बीच के contract और संबंधों पर ध्यान न दिया जाए, तो bug पैदा होते हैं
Equalcase को ignore करता है, लेकिनHashlowercased value का इस्तेमाल करता है। मगरEqualFoldऔरToLowerएक जैसा equivalence relation define नहीं करतेhttps://github.com/golang/go/issues/52204
"\u017F"(ſ, long s) और"s"EqualFoldमें बराबर हैं, लेकिनToLowerकरने पर दोनों के नतीजे अलग आते हैं। इसलिए पहले"s"डालने के बाद"ſ"डालें, तो hash अलग होने की वजह से वह अलग entry के रूप में insert हो जाता हैऔर भी दिलचस्प बात यह है कि documentation में इसी case के बारे में सीधे चेतावनी दी गई है
https://github.com/golang/go/…
https://github.com/golang/go/…
अच्छा लगा कि Anton जहाँ रुके थे, वहाँ से किसी और ने आगे बढ़ाया
मुझे Go पसंद है, लेकिन हर रिलीज़ में इस तरह फीचर जोड़ते रहने पर यह सवाल उठता है कि Go syntax पर्याप्त रूप से elegant है भी या नहीं
func (b Box[T]) Map[U any](f func(T) U) Box[U] {वहीं Go और Zig की verbosity का फायदा यह है कि receiver definition खोजने के लिए कहीं और scroll नहीं करना पड़ता। Call site, जो definition से भी ज़्यादा महत्वपूर्ण माना जा सकता है, वहाँ सब लगभग एक जैसे दिखते हैं और type को explicitly लिखने की भी ज़रूरत नहीं होती
मैं कुछ समय से Go से दूर था, इसलिए jsonv2 को लेकर उत्साहित हूँ। लेकिन अगर यह default बनता है, तो क्या Go लंबे समय से निभाए जा रहे compatibility promise को तोड़ नहीं देगा?
encoding/json/v2से import करना पड़ता है, इसलिए इसे जानबूझकर चुनना होता है। मौजूदाencoding/jsonअंदर से v2 का इस्तेमाल करता है, लेकिन पुराना behavior बनाए रखता है, और jsonv2 में v1 के exceptional behavior को दोहराने के लिए flags भी दिए गए हैं, इसलिए compatibility promise नहीं टूटता