Re: [go-nuts] Rethink possibility to make circular imports

2018-11-30 Thread Richard Wilkes
I've found that I end up lumping a bunch of things together into a much larger package than I'd prefer precisely because there is often no good way to break a logical piece out into its own package without creating a circular dependency. For me at least, this makes the code harder to navigate b

Re: [go-nuts] recursion plus goroutines

2018-11-30 Thread Alex Dvoretskiy
Yes! This is perfect! On Friday, November 30, 2018 at 2:52:57 PM UTC-8, Justin Israel wrote: > > > > On Sat, Dec 1, 2018, 10:43 AM Alex Dvoretskiy > wrote: > >> Here is recursion. I d'ont know when its end. >> > > Do you mean that you want to wait for all 3 goroutines to complete? > > var wg syn

Re: [go-nuts] recursion plus goroutines

2018-11-30 Thread Justin Israel
On Sat, Dec 1, 2018, 10:43 AM Alex Dvoretskiy wrote: > Here is recursion. I d'ont know when its end. > Do you mean that you want to wait for all 3 goroutines to complete? var wg sync.WaitGroup wg.Add(3) go func() { inOrderTr(root) wg.Done() }() go func() { preOrderTr(root) wg.

Re: [go-nuts] recursion plus goroutines

2018-11-30 Thread Alex Dvoretskiy
Here is recursion. I d'ont know when its end. On Friday, November 30, 2018 at 12:04:42 PM UTC-8, Burak Serdar wrote: > > On Fri, Nov 30, 2018 at 12:44 PM Alex Dvoretskiy > > wrote: > > > > Hi, > > > > How should I modify my code if I want to run three recursive functions > in parallel? > >

Re: [go-nuts] pointer dereference optimization in loops

2018-11-30 Thread robert engels
According to Dobb’s, http://www.drdobbs.com/cpp/type-based-alias-analysis/184404273 , many compilers do this today to some degree. > On Nov 30, 2018, at 2:51 PM, robert engels wrote: > > I’m not so sure about this case, as a smar

Re: [go-nuts] pointer dereference optimization in loops

2018-11-30 Thread robert engels
I’m not so sure about this case, as a smart compiler might decide the loop warrants alias checking, and then might only perform a single load and store and perform all of the computations in registers (or unroll them completely). I am not aware of compilers doing this today, but they certainly c

Re: [go-nuts] recursion plus goroutines

2018-11-30 Thread Burak Serdar
On Fri, Nov 30, 2018 at 12:44 PM Alex Dvoretskiy wrote: > > Hi, > > How should I modify my code if I want to run three recursive functions in > parallel? > > go inOrderTr(root) > go preOrderTr(root) > go postOrderTr(root) Those three are mutually independent, and the tree is read-only, so you do

[go-nuts] recursion plus goroutines

2018-11-30 Thread Alex Dvoretskiy
Hi, How should I modify my code if I want to run three recursive functions in parallel? go inOrderTr(root) go preOrderTr(root) go postOrderTr(root) https://play.golang.org/p/n-QLR7V0H49 -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsub

Re: [go-nuts] pointer dereference optimization in loops

2018-11-30 Thread robert engels
Then rewrite it this way func SomeFunc() { count:= 1 p := &count total := 0 for i:=0;i<10;i++ { total = total + *p someOtherFunc() } } it should definitely be optimized away in this case. > On Nov 30, 2018, at 12:09 PM, Jakob Borg wrote: > >

Re: [go-nuts] pointer dereference optimization in loops

2018-11-30 Thread Burak Serdar
On Fri, Nov 30, 2018 at 11:09 AM Jakob Borg wrote: > > This should only be valid for a loop that doesn’t include any function calls, > or if the compiler can prove that said function calls don’t involve any > synchronization primitives anywhere in the possible call stack. ...or any potential po

Re: [go-nuts] pointer dereference optimization in loops

2018-11-30 Thread Jakob Borg
This should only be valid for a loop that doesn’t include any function calls, or if the compiler can prove that said function calls don’t involve any synchronization primitives anywhere in the possible call stack. So maybe it’s optimized in for … { total += *p } but I wouldn’t bet on it in

Re: [go-nuts] pointer dereference optimization in loops

2018-11-30 Thread robert engels
I would think the compiler would be free to optimize this as a single load outside the loop - as Go has no volatile declaration (to inform the compiler that some other thread might of changed the value of *p) > On Nov 30, 2018, at 11:58 AM, robert engels wrote: > > It’s as simple as: > > var

Re: [go-nuts] pointer dereference optimization in loops

2018-11-30 Thread robert engels
It’s as simple as: var count = 1 var p = &count func X() { total :=0 for i:=0; i <100;i++ { total = total + *p } } no ? > On Nov 30, 2018, at 11:48 AM, Mark Volkmann wrote: > > I think I failed to come up with a good code example. But suppose I need to > do something with a point

Re: [go-nuts] pointer dereference optimization in loops

2018-11-30 Thread Mark Volkmann
I think I failed to come up with a good code example. But suppose I need to do something with a pointer inside a loop that really does require dereferencing it and the pointer never changes inside the loop. In that case will the Go compiler optimize that so the dereference doesn't happen in each lo

Re: [go-nuts] pointer dereference optimization in loops

2018-11-30 Thread Jan Mercl
On Fri, Nov 30, 2018 at 6:16 PM Mark Volkmann wrote: > Will the Go compiler optimize the pointer dereference so it doesn't happen in every loop iteration? If not, is it common practice to do that outside the loop like this? > > myValue := *myPtr > for _, v := range values { > fmt.Printf("

[go-nuts] pointer dereference optimization in loops

2018-11-30 Thread Mark Volkmann
Suppose myPtr is a pointer and I write code like this: for _, v := range values { fmt.Printf("%v %v\n", *myPtr, v) } Will the Go compiler optimize the pointer dereference so it doesn't happen in every loop iteration? If not, is it common practice to do that outside the loop like this? myValue :=

Re: [go-nuts] Rethink possibility to make circular imports

2018-11-30 Thread roger peppe
In my view, Go's prohibition on cyclic imports is perhaps *the* single most important feature that keeps large Go projects sane. There are numerous occasions in the last few years when we would have used cyclic imports if they were available, and in every case it would have been a mistake. In some

Re: [go-nuts] When set time.Location, will be detected Data Race

2018-11-30 Thread Agniva De Sarker
Can you show us the code ? It would help Are you trying to set a variable of type time.Location ? Or are you trying to set time.Local to something else ? Like Ian said, if you want to change the location of a specific time value, use the In method. > But there are lots of place that time.Loca

Re: [go-nuts] GC - Absolute Timestamp and Pause Time calculation

2018-11-30 Thread Ian Lance Taylor
On Fri, Nov 30, 2018 at 6:42 AM Prabhash Rathore wrote: > > I need to analyze the Golang GC log, specifically the pause times wrt to the > server time (absolute time). However I see the Golang gGC log does not > contain absolute timestamp, it has a relative timestamp from the process > start ti

Re: [go-nuts] Scaling websockets

2018-11-30 Thread Robert Engels
It is not a websocket issue it is a design issue. Either the notification service needs to subscribe to the MQ channel for each user logged into that service, or it needs to subscribe for a group of users, or all users. Sounds like you are doing all users, and it is not working but you don’t sa

Re: [go-nuts] When set time.Location, will be detected Data Race

2018-11-30 Thread Marvin Renich
* Ian Lance Taylor [181130 01:01]: > On Thu, Nov 29, 2018 at 9:47 PM wrote: > > The feature of golang is goroutine, and it is a normal situation that get > > time in different goroutine. > > But only can set time.Location in one goroutine. So the Data Race is > > inevitable. > > > > And there i

Re: [go-nuts] Rethink possibility to make circular imports

2018-11-30 Thread Burak Serdar
On Fri, Nov 30, 2018 at 6:50 AM Michel Levieux wrote: > > Hi guys, > > I've been trying to find examples of cases where it is complicated to > structure the project because circular imports are forbidden, but I can't > find something simple that I can show you. The thing is when I've been > con

Re: [go-nuts] [ANN] fixed point math library

2018-11-30 Thread Bakul Shah
This is quite clever but you really don’t want to have to define types for all of the currencies in use where most people deal with one or few at most. Worse, new currencies may come into existence at any time. And consider securities such as stocks, bonds etc. which have some similar operations bu

[go-nuts] Scaling websockets

2018-11-30 Thread GolangUser
Hi, The scenario is, a web socket connection is being created to server side application say NotificationService whenever a user login to our website. The NotificationService has been deployed on 5 instances. The event driven service filters the incoming events and broadcast the processed user

[go-nuts] GC - Absolute Timestamp and Pause Time calculation

2018-11-30 Thread Prabhash Rathore
Hello, I need to analyze the Golang GC log, specifically the pause times wrt to the server time (absolute time). However I see the Golang gGC log does not contain absolute timestamp, it has a relative timestamp from the process start time. Is there a reason not to log absolute timestamp with ea

Re: [go-nuts] Rethink possibility to make circular imports

2018-11-30 Thread Josh Humphries
On Fri, Nov 30, 2018 at 8:50 AM Michel Levieux wrote: > Hi guys, > > I've been trying to find examples of cases where it is complicated to > structure the project because circular imports are forbidden, but I can't > find something simple that I can show you. The thing is when I've been > confron

Re: [go-nuts] Rethink possibility to make circular imports

2018-11-30 Thread Jamie Clarkson
I've been trying to find examples of cases where it is complicated to > structure the project because circular imports are forbidden, but I can't > find something simple that I can show you. The thing is when I've been > confronted to such cases, it was with large projects, and I have no simpl

Re: [go-nuts] Rethink possibility to make circular imports

2018-11-30 Thread Michel Levieux
Hi guys, I've been trying to find examples of cases where it is complicated to structure the project because circular imports are forbidden, but I can't find something simple that I can show you. The thing is when I've been confronted to such cases, it was with large projects, and I have no simple