在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
Introduction to Go 1.4The latest Go release, version 1.4, arrives as scheduled six months after 1.3. It contains only one tiny language change, in the form of a backwards-compatible simple variant of The release focuses primarily on implementation work, improving the garbage collector and preparing the ground for a fully concurrent collector to be rolled out in the next few releases. Stacks are now contiguous, reallocated when necessary rather than linking on new "segments"; this release therefore eliminates the notorious "hot stack split" problem. There are some new tools available including support in the As always, Go 1.4 keeps the promise of compatibility, and almost everything will continue to compile and run without change when moved to 1.4. Changes to the languageFor-range loopsUp until Go 1.3, for i, v := range x { ... } and for i := range x { ... } If one was not interested in the loop values, only the iteration itself, it was still necessary to mention a variable (probably the blank identifier, as in for range x { ... } was not syntactically permitted. This situation seemed awkward, so as of Go 1.4 the variable-free form is now legal. The pattern arises rarely but the code can be cleaner when it does. Updating: The change is strictly backwards compatible to existing Go programs, but tools that analyze Go parse trees may need to be modified to accept this new form as the Method calls on **TGiven these declarations, type T int func (T) M() {} var x **T both x.M() which is a double dereference of the pointer-to-pointer Updating: Code that depends on the old, erroneous behavior will no longer compile but is easy to fix by adding an explicit dereference. Changes to the supported operating systems and architecturesAndroidGo 1.4 can build binaries for ARM processors running the Android operating system. It can also build a NaCl on ARMThe previous release introduced Native Client (NaCl) support for the 32-bit x86 ( Plan9 on AMD64This release adds support for the Plan 9 operating system on AMD64 processors, provided the kernel supports the Changes to the compatibility guidelinesThe We have clarified this situation in the documentation included in the release. The Go compatibility guidelines and the docs for the Updating: Nothing technical has changed; this is just a clarification of the documentation. Changes to the implementations and toolsChanges to the runtimePrior to Go 1.4, the runtime (garbage collector, concurrency support, interface management, maps, slices, strings, ...) was mostly written in C, with some assembler support. In 1.4, much of the code has been translated to Go so that the garbage collector can scan the stacks of programs in the runtime and get accurate information about what variables are active. This change was large but should have no semantic effect on programs. This rewrite allows the garbage collector in 1.4 to be fully precise, meaning that it is aware of the location of all active pointers in the program. This means the heap will be smaller as there will be no false positives keeping non-pointers alive. Other related changes also reduce the heap size, which is smaller by 10%-30% overall relative to the previous release. A consequence is that stacks are no longer segmented, eliminating the "hot split" problem. When a stack limit is reached, a new, larger stack is allocated, all active frames for the goroutine are copied there, and any pointers into the stack are updated. Performance can be noticeably better in some cases and is always more predictable. Details are available in the design document. The use of contiguous stacks means that stacks can start smaller without triggering performance issues, so the default starting size for a goroutine's stack in 1.4 has been reduced from 8192 bytes to 2048 bytes. As preparation for the concurrent garbage collector scheduled for the 1.5 release, writes to pointer values in the heap are now done by a function call, called a write barrier, rather than directly from the function updating the value. In this next release, this will permit the garbage collector to mediate writes to the heap while it is running. This change has no semantic effect on programs in 1.4, but was included in the release to test the compiler and the resulting performance. The implementation of interface values has been modified. In earlier releases, the interface contained a word that was either a pointer or a one-word scalar value, depending on the type of the concrete object stored. This implementation was problematical for the garbage collector, so as of 1.4 interface values always hold a pointer. In running programs, most interface values were pointers anyway, so the effect is minimal, but programs that store integers (for example) in interfaces will see more allocations. As of Go 1.3, the runtime crashes if it finds a memory word that should contain a valid pointer but instead contains an obviously invalid pointer (for example, the value 3). Programs that store integers in pointer values may run afoul of this check and crash. In Go 1.4, setting the AssemblyThe language accepted by the assemblers First, the #include "textflag.h" The more important changes are in how assembler source can define the necessary type information. For most programs it will suffice to move data definitions ( Updating: Assembly files that include More information about these changes is in the assembly document. Status of gccgoThe release schedules for the GCC and Go projects do not coincide. GCC release 4.9 contains the Go 1.2 version of gccgo. The next release, GCC 5, will likely have the Go 1.4 version of gccgo. Internal packagesGo's package system makes it easy to structure programs into components with clean boundaries, but there are only two forms of access: local (unexported) and global (exported). Sometimes one wishes to have components that are not exported, for instance to avoid acquiring clients of interfaces to code that is part of a public repository but not intended for use outside the program to which it belongs. The Go language does not have the power to enforce this distinction, but as of Go 1.4 the To create such a package, place it in a directory named For Go 1.4, the internal package mechanism is enforced for the main Go repository; from 1.5 and onward it will be enforced for any repository. Full details of the mechanism are in the design document. Canonical import pathsCode often lives in repositories hosted by public services such as Go 1.4 introduces an annotation for package clauses in Go source that identify a canonical import path for the package. If an import is attempted using a path that is not canonical, the The syntax is simple: put an identifying comment on the package line. For our example, the package clause would read: package pdf // import "rsc.io/pdf" With this in place, the The check is at build time, not download time, so if To complement this new feature, a check has been added at update time to verify that the local package's remote repository matches that of its custom import. The Further information is in the design document. Import paths for the subrepositoriesThe Go project subrepositories ( Updating: All code that imports from subrepositories should change to use the new The go generate subcommandThe For more information, see the design document. Change to file name handlingBuild constraints, also known as build tags, control compilation by including or excluding files (see the documentation Before Go 1.4, a file called just Updating: Packages that depend on the old behavior will no longer compile correctly. Files with names like Other changes to the go commandThere were a number of minor changes to the
Changes to package source layoutIn the main Go source repository, the source code for the packages was kept in the directory Updating: Tools like SWIGDue to runtime changes in this release, Go 1.4 requires SWIG 3.0.3. MiscellanyThe standard repository's top-level The Go community at large is much better suited to managing this information. In Go 1.4, therefore, this support has been removed from the repository. Instead, there is a curated, informative list of what's available on a wiki page. PerformanceMost programs will run about the same speed or slightly faster in 1.4 than in 1.3; some will be slightly slower. There are many changes, making it hard to be precise about what to expect. As mentioned above, much of the runtime was translated to Go from C, which led to some reduction in heap sizes. It also improved performance slightly because the Go compiler is better at optimization, due to things like inlining, than the C compiler used to build the runtime. The garbage collector was sped up, leading to measurable improvements for garbage-heavy programs. On the other hand, the new write barriers slow things down again, typically by about the same amount but, depending on their behavior, some programs may be somewhat slower or faster. Library changes that affect performance are documented below. Changes to the standard libraryNew packagesThere are no new packages in this release. Major changes to the librarybufio.ScannerThe Updating: Custom split functions may need to be modified to handle empty tokens at EOF as desired. syscallThe A new subrepository, golang.org/x/sys, has been created to serve as the location for new developments to support system calls on all kernels. It has a nicer structure, with three packages that each hold the implementation of system calls for one of Unix, Windows and Plan 9. These packages will be curated more generously, accepting all reasonable changes that reflect kernel interfaces in those operating systems. See the documentation and the article mentioned above for more information. Updating: Existing programs are not affected as the Minor changes to the libraryThe following list summarizes a number of minor changes to the library, mostly additions. See the relevant package documentation for more information about each change.
|
请发表评论