Go 1.9 is released(blog.golang.org) |
Go 1.9 is released(blog.golang.org) |
Build time with 1.8.3:
real 0m7.533s
user 0m36.913s
sys 0m2.856s
Build time with 1.9: real 0m6.830s
user 0m35.082s
sys 0m2.384s
Binary size: 1.8.3 : 19929736 bytes
1.9 : 20004424 bytes
So... looks like the multi-threaded compilation indeed delivers better build times, but the binary size has increased slightly.[1] You can git-clone and try yourself: https://github.com/gravitational/teleport
Furthermore, when I see a second run that's faster than the first one, I immediately wonder if it's the cache being cold for the first run and warm for the second.
While I have your attention, https://zedshaw.com/archive/programmers-need-to-learn-statis... is worth reading.
PSA: There is no reason to behave like this and this is an incredible way to alienate a bunch of people. You either offend people directly with the murder implication or they don't take you seriously because you sound like you're throwing such an extended temper tantrum that you managed to write it all in a blog.
how, concretely, should I go about doing this particular analyzis of compile time for one project ? How many times should I run the build for each of the 2 compilers and what should I do with the result so I could; 1. Draw a conclusion 2. Come up with fair numbers of how they compare ?
I would hope someone could tech this hopefully simple and very concrete thing to the HN crowd and I do hope the answer is not "go learn statistics".
Not by default. You have to set CGO_ENABLED=0 to statically link libc.
func testServer(t *testing.T, port int) {
...do stuff...
if err != nil { t.Fatalf("failed to start server: %+v", err) }
}
similarly you can have func assertMapEquals(t *testing.T, a, b map[string]int)
It lets you hide such helper methods from the test failure's stack trace (where t.Fatal is actually called), making test errors more readable.Come join if your near the area.
https://en.wikipedia.org/wiki/Type_safety
> Type enforcement can be static, catching potential errors at compile time, or dynamic, associating type information with values at run-time and consulting them as needed to detect imminent errors, or a combination of both.
interface{} is type-checked at runtime. It's type-safe because because you can't e.g. fish out an integer out of interface{} value that represents a string. Runtime won't allow it.
You can either extract a string or the runtime will crash if you insist on extracting anything else. Unless you use unsafe package, in which case you explicitly want to skip type-safety.
"Mutex is now more fair."
Source: https://golang.org/doc/go1.9#syncDoes anyone know what that means?
1. runtime/pprof package now include symbol information
2. Concurrent Map
3. Profiler Labels
4. database/sql reuse of cached statements
5. The os package now uses the internal runtime poller for file I/O.
!! that wasn't a thing until now?
See https://golang.org/doc/go1.9#database/sql
Go 1.9 adds reuse of statement handles created off an ephemeral transaction too. But all the other statement handle cases have cached from day 1.
I see there's (more) parallel compilation in 1.9 - so that should improve elapsed time (but not reduce cpu time) of compilation.
Would be nice to know if 1.9 is (still) on track catch up to/pass 1.4.
[1] https://dave.cheney.net/2016/11/19/go-1-8-toolchain-improvem...
Go 1.4: Around 2.1s Go 1.9: Around 2.5s
So within 20% of 1.4, not bad. That's on an old MacBook Air, dual core 1.7 GHz i7, 8GB ram.
And of course the binary performance and GC pause times w/ 1.9 will be much better.
Here's the raw times: https://pastebin.com/ULDHPmVu
Two awesome things:
It was super-easy and fast to download and compile Go 1.4
It was completely painless to compile my old code with Go 1.9
I fucking love how nice it is to work with the Go ecosystem. <3
Reality is that the Linux Kernel makes a big confusion between processes and threads in the userspace APIs.
Locking to threads is a solution that works but also sucks and defeats the niceties of Go N:M model. But that's the only way: if you use that broken system calls API you should know better.
So basically it's designed for cases like 'I have N goroutines and each one owns 1/N keys'?
With those constraints, why not create a small map for each goroutine at that point, and merge the maps afterwards?
fatal error: concurrent map writes // file tree.go
type T = YourConcreteType
type TreeNode struct {
Value T
}
// rest of tree implementation
Then you can just copy the file and replace YourConcreteType at the top and voila!Seems simpler to use than the unicode hack here https://www.reddit.com/r/rust/comments/5penft/parallelizing_...
I googled a little bit and found some good info, I guess I had forgotten a little bit of the concepts of mutex fairness/unfairness. I found a very nice explanation on cs.stackexchange:
"My understanding is that most popular implementations of a mutex (e.g. std::mutex in C++) do not guarantee fairness -- that is, they do not guarantee that in instances of contention, the lock will be acquired by threads in the order that they called lock(). In fact, it is even possible (although hopefully uncommon) that in cases of high contention, some of the threads waiting to acquire the mutex might never acquire it."
Source: https://cs.stackexchange.com/questions/70125/why-are-most-mu...With that computer science clarification, I think the comment "Mutex is now more fair" and the detailed description "Unfair wait time is now limited to 1ms" makes it a lot clearer.
Great improvement I think! It's one of those things that you don't notice until you have a bug, but it's really nice to never get that bug in the first place. =)
> Mutex fairness.
> Mutex can be in 2 modes of operations: normal and starvation.
> In normal mode waiters are queued in FIFO order, but a woken up waiter
> does not own the mutex and competes with new arriving goroutines over
> the ownership. New arriving goroutines have an advantage -- they are
> already running on CPU and there can be lots of them, so a woken up
> waiter has good chances of losing. In such case it is queued at front
> of the wait queue. If a waiter fails to acquire the mutex for more than 1ms,
> it switches mutex to the starvation mode.
> In starvation mode ownership of the mutex is directly handed off from
> the unlocking goroutine to the waiter at the front of the queue.
> New arriving goroutines don't try to acquire the mutex even if it appears
> to be unlocked, and don't try to spin. Instead they queue themselves at
> the tail of the wait queue.
> If a waiter receives ownership of the mutex and sees that either
> (1) it is the last waiter in the queue, or (2) it waited for less than 1 ms,
> it switches mutex back to normal operation mode.
> Normal mode has considerably better performance as a goroutine can acquire
> a mutex several times in a row even if there are blocked waiters.
> Starvation mode is important to prevent pathological cases of tail latency.
Not that I would want this in my project. But as a hack, it’s even better than it first sounds.
Was that interpreted as a complaint as well? Is that the problem?
https://news.ycombinator.com/newsguidelines.html
"Please don't comment about the voting on comments. It never does any good, and it makes boring reading."
Also, do you have any good references to proper best practices around concurrent and parallel programming? (in Go.) Like just basic things. Code I can copy and paste without it having obscure race conditions because that use of mutex is absolutely correct, and something that lets me understand the limitations. I feel like it is very easy to do things "wrong" or not notice some edge cases. In C++ I didn't only ever coded single-threaded for this reason. Too many gotchas. Any help would be appreciated.
For example, one might say "static code analysis" to mean analyzing code without running it, such as during a phase during compilation. In contrast, "dynamic code analysis" tends to mean actually running the code and making decisions based on what happens at runtime, such as in JIT (https://en.wikipedia.org/wiki/Just-in-time_compilation) techniques that identify hotspots.
Given that it's a pretty big distinction I would think it's on the speaker to be un-ambiguous and say "it's not statically type safe" vs. ambiguous "type safe".
I've certainly seen my share of people claiming that "interface{} is just like void * in C" when they speak about Go's (lack of) type safety.
I also don't see how insisting on accurate and un-ambiguous terminology ticks people off so much to downvote. I imagine they think I said something much more incorrect than I did.
I would note that the Wikipedia page does not take as strong a position as you seem to imply, reading:
> In the context of static (compile-time) type systems, type safety usually involves (among other things) a guarantee that the eventual value of any expression will be a legitimate member of that expression's static type. The precise requirement is more subtle than this — see, for example, subtype and polymorphism for complications.
Since golang is statically typed, type safety is generally understood to mean static type safety.
Beyond that, you need to run the same build "several" times to see what the variance is. Without getting specific, if the builds are within a couple percent of each other, do "a few" and take the mean. If they're all over the place do "lots" and only stop once the mean stabilises. There are specific methods to define "lots" and "a few" but it's usually obvious for large effects and you don't need to worry too much about it.
If you're trying to prove that you've made a 0.1 improvement on an underlying process that is normally distributed with a stddev of, like 2, then you're going to have to run it a lot and do some maths to show when to stop and accept the result.
It's all about measuring based on what you intend to use the measurements for.
I don't myself lose much sleep over worrying about the times it runs faster than possible.
Of course, as I said in another comment it depends what you want to do with the measurement. If you plan to edit how long a run will take on an existing system, then you need to accept the noise and use the mean (or median).
Personally I think it's a better idea to instrument your programs and count the number of memory (block) accesses or something. That metric might actually be useful to a reader a few years in the future. The fact that your program was running faster on a modern x86 processor from the year 2010 tells me nothing about how it would perform today, unless the difference was so large that you never needed statistical testing in the first place...
edit: I'm not sure if this paper is accessible to everyone, so here is an alternate link https://hal.inria.fr/inria-00443839v1/document
Funny. The first thing that came to mind was:
import (
bar "github.com/name/bar"
baz "github.com/name/baz"
foo "github.com/name/foo"
foo_bar "foo<A=bar, B=baz>"
)It infuriates me when go proponents try and sweep bad language decisions under the rug with half-fixes.
Mind you, if third party code needs debugging, you're going to have to fork it in order to apply your fixes in a timely manner anyway. Perhaps their stance is not as crazy as it may originally seem.
When you rely on dependencies you have to expect that not all of them will carry the same quality of code which you create yourself.
exceptions are a curse.
$ cat foo.go
package main
import (
"fmt"
)
func main() {
fmt.Println("Hello")
}
$ go build foo.go
$ file foo
foo: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped
compared to: $ cat bar.go
package main
import (
"os/user"
"fmt"
)
func main() {
u, err := user.Current()
fmt.Println(u, err)
}
$ go build bar.go
$ file bar
bar: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, not strippedAnything can panic in Go. Go gives absolutely no guarantee something cannot panic. Errors as values are just a convention. So exceptions are a curse but Go has an inferior exception system, panics, but they are still exceptions.
The solution is checked exceptions.
I'm seriously beginning to think that even with the limitations, panic is a better error handling mechanism for all exceptional error cases. At least it has stacktraces and doesn't clutter the code with error boilerplate. I don't think I'd be able to convince anyone of that on a real project though, I'd have to try it on a personal project.
Now if it said "Go code is usually/by default statically linked", then yes.
CGO_ENABLED=0 go build
even when using os/user or net/Happened here recently - modules used in the core build aren't versioned which means when someone external updated a module with an incompatible change, the build broke.
Moral: Never build direct from CPAN / GOPAN / CCAN / WHATEVSPAN without pinned versions.
I don't want to insult anyone, but this seems like an utterly insane software engineering practice to me. It means you can't just update to the next version of that library any longer. You're taking it upon yourself to review and patch every single new version of that library. Manually.
Even vendoring, which was added to the tooling later, is built on the idea of keeping your own fork. It just simplifies the forking process for people who do not work like Google does, where each fork is shared company-wide.
Not only are people here suggesting that you fork your dependencies to add stack traces to errors, which is a problem no other modern language seems to have, but it's also going to be a security disaster when some common package is found to have a vulnerability and ten percent of projects ever bother to update it.
I feel like I've entered some sort of bizarro world where everyone has forgotten that programming doesn't have to suck and pretends that none of this is a problem.
Can't get stack traces from third-party errors? Maintain all of your dependencies! Tired of reimplementing common math functions? Just cast all your numerics to double! And so on...
Again, this may be a poor operational choice for those outside of Google, but they have also been quite clear that Go is built for the problems that Google has. If your problems are different, it may not be the right tool for the job. A hammer doesn't have to be able to cut wood. There is no harm in choosing a saw instead.
>the Go authors have always strongly promoted that you fork and maintain your dependencies
And you said that in response to a need for stack traces and specific error types.
Burdening yourself with maintaining a fork of a third party library for that specific purpose is what I'm calling insane, and I don't think the Go authors have ever suggested such a thing.
Which is true. Their stance on maintaining your own forks is pervasive through all the tooling and their explanations of how the tools are designed to be used. There has been emphasis that if you want the tools to work well, you need to fork and maintain your dependencies.
You are, of course, free to do whatever you want. You can even feely let a random third-party maintain your dependencies, and hope they don't break anything, if you so wish. Many do exactly that. Despite what some people like to claim, the Go authors are not benevolent dictators that completely rule how you must develop software. They've simply published tools that worked for them, and granted a license that allows you to use and modify them in any way you see fit.
> And you said that in response to a need for stack traces and specific error types.
Technically the discussion was about how stack traces aid in debugging. It is a fair point. They most certainly do. And if you are interested in the stack within a third-party library, that suggests that you intend to debug said library.
If you are debugging a third-party package, you have already decided to fork it by virtue of what debugging requires. Adding stack traces to ease debugging of the package, if you so desire, is not a great undertaking on what is already a fork you have decided to maintain. You, of course, can submit your changes to the upstream maintainer, but in the meantime you are still holding on to a fork that you have decided to maintain. There is no guarantee that anyone else will want your changes. There is really no escaping that fact. It is not insane. It is simply pragmatic.
If you are only ever going to maintain your own code, the stack trace up to your call out to the buggy third-party package will still be available, if you choose to provide it, allowing you to work around or otherwise deal with the buggy package in your code.
I think we disagree on two separate issues that shouldn't be conflated.
The first issue is whether the only purpose of a stack trace coming from a third party library is to actually debug that library. I suggest that this is not the the case.
I may simply want to understand what's going on in there. Maybe I'm passing incorrect data to that library, but the returned error is not specific enough to tell me what I did wrong. Maybe the error is somewhere further down in my own code (e.g. in a callback), in a different library altogether or related to the environment (missing file, broken database connection, ..). Or I may just want to post the stack trace in a support forum to get help.
I have often been looking at stack traces from third party libraries, but I have rarely wanted to debug those libraries.
Our second disagreement is perhaps a more gradual one. You seem to suggest that maintaining a fork is something completely normal or even desirable. I think it is something extremely undesirable - a last resort.
In any case, I do not believe that the Go creators have ever suggested that maintaining a fork is something you should do willy nilly or something that everybody should do all the time. This is different from the use of vendoring for versioning purposes. If the Go creators did in fact promote such a thing, I would strongly disagree with them.
If you have found stack traces are already readily available in third-party packages – that you can claim you do it often – what's the issue? Maybe this thread would be better served by real world examples of where the lack of stack traces in Go has actually bitten you?
> Maybe the error is somewhere further down in my own code (e.g. in a callback)
To be fair, the Go authors have also driven home the fact that you need to make your errors meaningful with the full context necessary to determine the path of the error (granted, not necessarily a full-fledged call stack). They have been abundantly clear that you should never simply `return err`. If this is an issue, it is because the code was written poorly.
And if a package is written poorly, and you don't want to fix the issues with it, perhaps you should reconsider using it in the first place?
> This is different from the use of vendoring for versioning purposes.
How so? The simplest form of a fork is one that is an exact copy of the original. If a package is already suitable to your needs, there is no reason to modify it, other than to perhaps merge in updates that the upstream author has made.
You can either keep that fork in a global repository, or you can keep it in vendor. There is no fundamental difference between either of those. At all. Vendor is just a convenience feature to allow the fork to stay in your application's tree.
Of course, if the library is poorly written or doesn't perfectly suit your needs you may have to make modifications to it. But that is true of every library written in every language in existence. It is not insane to do that, just pragmatic.
Not in Go. I have found them extremely useful as a diagnostic tool in languages that have ubiquitous stack traces.
>And if a package is written poorly, and you don't want to fix the issues with it, perhaps you should reconsider using it in the first place?
As I said, the problem may not even originate in that particular third party library. The error may just be passing through, coming from my own code or from a different library altogether.
>How so? The simplest form of a fork is one that is an exact copy of the original.
Vendoring is not primarily about forking and then changing the code. The main purpose of vendoring is freezing dependencies.
Then you will have a stack trace to work with. Again, this discussion would be more meaningful if you provided some real world examples. Hypothetical situations that will never happen in the real world are kind of pointless. You don't have to invent reasons to justify not using Go, if that is your intent. Frankly, I couldn't care less what tools you use, and it seems like it is justifiably not the right tool for your problems to begin with.
> Vendoring is not primarily about forking and then changing the code. The main purpose of vendoring is freezing dependencies.
But you are quite literally maintaining a fork. In 99% of the cases there will be no need to modify the code, be it in vendor or in another repository. Freezing the dependency has always been the primary goal of both approaches. The only difference vendor introduced is that the code resides under the vendor tree of each individual application, instead of in a global namespace that allows you to share your pinned version with all of your applications. That's it.
Only if a stack trace was added in the original location and then passed on at each intermediate step. As stack traces are not automatically created in Go, nor customarily passed on, there is usually no stack trace available.
>Again, this discussion would be more meaningful if you provided some real world examples. Hypothetical situations that will never happen in the real world are kind of pointless. You don't have to invent reasons to justify not using Go, if that is your intent.
I have been a real world developer for 25 years, and I have explained to you the sort of real life situations in which I have used stack traces to diagnose errors, either originating in or bubbling up through third party code.
If you want to call me a liar, fine, but otherwise don't call it a hypothetical situation that will never occur if I'm telling you that I have run into countless such situations.
I have been using Go and I have defended it on many occasions. But this sort of obstinate reaction of denial and deflection to the most obvious difficulties caused by any of Go's design decisions is really starting to put me off big time.
>But you are quite literally maintaining a fork. In 99% of the cases there will be no need to modify the code
Inserting error handling code is a modification and keeping it up-to-date with new versions of the library is the problem I'm talking about. I think I have made that very clear before.