After fixing the bugs pointed out by Michael (I'm incompetent), here are
the new results:
Uninterned-8120ms ą18%
Map-8 140ms ą 2%
LockedMap-8 139ms ą 2%
LockedParellel-8146ms ą 2%
SyncMap-8 253ms ą 4%
SyncMapParallel-8 109ms ą 9
> In terms of lookup/insertion/etc., I would expect unique.Make to perform
> much better than a locked map when doing operations in parallel, but
> perform slightly worse when everything is done on a single core.
It looks like your intuition was correct. Sync.Map still performs
better, though.
> In terms of lookup/insertion/etc., I would expect unique.Make to perform
> much better than a locked map when doing operations in parallel, but
> perform slightly worse when everything is done on a single core.
Thanks, that's encouraging. I'll see if I can conjure a realistic
benchmark.
--
Yo
Hi,
Does anyone have any benchmarks for the new "unique" package? How does
it compare with manual interning using a map?
Thanks.
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it,
> I don't know if JSON serialization is deterministic, but I know a couple
> of cases when it is not.
> If the type or some type inside it has a custom JSON marshaller (method
> MarshalJSON), then if that function's output is not deterministic, the
> whole JSON for the type is not deterministic.
Hi,
Suppose that I call json.Marshal on two structures that are deep equal,
or on the same structure at different times. Are the outputs guaranteed
to be bytewise identical?
(The reason I'm asking is that I'm sending JSON over HTTP, and I need to
know whether it is correct to send a strong ETag
> Apparently wine 9.0 rc2 includes bcryptprimitives.dll now (I tested on it
> and it did work).
Thanks for the hint, it apparently works with 8.19 (wine-development in
Debian).
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from
> Apparently the change below broke Windows apps when running under Wine as
> it made bcryptprimitives.dll a hard requirement now and this dll is not
> bundled with Wine. This is true even for programs that do not use it all
> (like a simple "hello world" program).
>
> https://github.com/golang/go/
>> I took some time to put this to a test. The Go program here
>> https://go.dev/play/p/378Zn_ZQNaz uses a VERY short holding of the
>> lock - but a large % of runtime holding the lock.
> Thanks for the benchmark. You're right: if you have hundreds of
> goroutines doing nothing but acquiring a re
> By stdlib, you presumably mean the x/net/websocket package,
Careful with this library, it's not quite correct. Websocket is
a frame-oriented protocol, while x/net/websocket implements a simplistic
API that does not always preserve frame boundaries.
Correct implementations include:
https://g
I'm writing a simple UDP server, and I'm trying to use the new net/netip
data types. My main loop starts as follows:
for {
n, a, err := sock.ReadFrom(buf)
if err != nil {
log.Printf("ReadFrom: %v", err)
time.Sleep(100 * time.Millisecond)
con
> Very interesting article came out recently.
> https://www.infoq.com/articles/java-virtual-threads/
Interesting article, thanks for the pointer.
> it has implications for the Go context discussion and the author makes
> a very good case as to why using the thread local to hold the
> context - ra
> I want to be able to terminate each worker independently of others
> (i.e. close on worker, wait for it to finish its tasks, but allow
> other workers to run if they haven't been signalled to stop).
The solution I use is to have each worker take two parameters:
- a channel that will be closed
Hi,
I'm working on an application (a thing with a "main" function) that has
a user-visible version. Since the internal modules of the project do
not have any backwards compatibility between versions, I've been tagging
releases with versions that the Go tools won't recognise (galene-0.3
instead of
> For example, on the Go side write
> type chanToUse struct {
> c chan int
> }
> //export MyGoFunction
> func MyGoFunction(u unsafe.Pointer, val int) {
> cu = (*chanToUse)(u)
> cu.c <- val
> }
Why the struct? Couldn't you just pass a pointer to a chan?
--
You received this message
>> Could you please give an example of the proposed syntax?
> func F[T constraints.Integer]() {
> switch T {
> case int:
> case int8:
> }
> }
Makes perfect sense, thanks.
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubs
> We’re going to permit type switches on type parameters that have type
> lists, without the “.(type)” syntax. The “(.type)” syntax exists to
> clarify code like “switch v := x.(type)”.
Could you please give an example of the proposed syntax?
--
You received this message because you are subscri
Axel Wagner writes:
> I feel like https://go2goplay.golang.org/p/RLn9BXjU1OR is a better
> compromise than having two functions.
> Prolly. Except OP specifically asked about "not that" :)
Agreed on both counts.
--
You received this message because you are subscribed to the Google Group
I'd be grateful if people could give me an example to help me understand
the generics draft. Suppose I've got these two functions:
func MemberInt(x int, a []int) bool {
for _, v := range a {
if v == x {
return true
}
}
>> Wondering why there's no http.ServeStream() API to do chunked
>> transfer-encoding (or the http2 equivalent), in addition to the nice
>> features of ServeContent()...
Uh-huh. It would be nice to be able to use the If-None-Match logic for
unseekable strings.
> Maybe because the current Serve
> One reason for not implementing it in the standard library is that there
> are many possible implementations. Do you want to reverse combining
> character sequences for example? Unicode is a complex beast and I suspect
> that reversing a string rune-by-rune may easily break important
> semantics.
It would be helpful if the introduction to the maphash package immediately
stated that it produces 64-bit values, and perhaps restate the fact that
the value can be safely reduced using bit masking (already there at the
Sum64 method).
I'm not sure what is the purpose of the BlockSize method -- why
The first time I ran go-1.14rc1 on a stock Debian system, I got:
runtime: mlock of signal stack failed: 12
runtime: increase the mlock limit (ulimit -l) or
runtime: update your kernel to 5.3.15+, 5.4.2+, or 5.5+
fatal error: mlock failed
ulimit -l is at 64, which is also the hard
> See https://golang.org/cl/36022.
There's a terrifying sort of beauty to it, like a tarantula or a snake.
(And it most certainly deserves a comment in the source.)
-- Juliusz
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from
>> for i:=c.Iterator();i.HasNext(); {
>> v := i.Next()
>> }
> I don't like the eyeball friction.
Could you please explain what you mean?
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving email
> You could also take a look
> at https://godoc.org/github.com/mailru/easygo/netpoll
I don't have a net.Conn, just a raw file descriptor.
-- Juliusz
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiv
> If you do this in Go, you should use golang.org/x/sys/unix package
> rather than the syscall package.
What's the advantage? (In this particular case, not in general.)
> But since you have to call C anyhow, I would suggest just doing it in C.
Yeah, I guess it's simpler.
> There isn't any way
I'm interfacing with a C library that expects to do its own I/O, but
wants to be called after a file descriptor is ready for read. My code
currently looks roughly like this:
var fdset syscall.FdSet
var bits = unsafe.Sizeof(fdset.Bits[0]) * 8
fdset.Bits[uintptr(fd)/bits] |= (1 << (fd %
>> https://play.golang.org/p/f_qy1ZI56w7
> Got it, thanks.
It took me a while. I think the point Ian is making is that an
unexported field is not CanSet.
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop
> Callbacks are rarely used in Go's ecosystem.
https://golang.org/pkg/sort/#Slice
https://golang.org/pkg/sync/#Map.Range
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an em
> i need to reset the tcp connection manually , if one request come from
> ipLayer.SrcIP
> = 10.2.3.1 then i need to sent the reset connection packet
I could be wrong, but I don't think the sockets API makes this
possible -- RST segments are normally only sent by the kernel upon
receiving a segmen
>> I believe using the non-destructive 3 operand form will help a lot in
>> reducing the size of binaries.
> We would have to make a clear decision as to the oldest amd64
> processor we wanted to support. Right now I believe we support all
> amd64 processors. Are we ready to give up on old ones?
> You can't take the address of the return value of a function or a
> conversion (which is conceptually just a function) because it doesn't
> have a location in memory and thus doesn't have an address.
I've never understood the reason for this limitation. I'd expect the
compiler to box any value
> cgo is not go.
The speed of system calls is similar though -- 110 microseconds for
a UDP send/receive pair over loopback. As compared to a single core of
a 2.4GHz laptop, the MIPS nodes are:
- 10 to 20 times slower on integer code;
- 30 times slower on small UDP packets over loopback;
BenchmarkGoCall 29.00 ns/op
BenchmarkCgoCall 100 2302 ns/op
2 microseconds to call into C. Ouch.
(That's on a 680MHz 24Kc core with 32kB data cache. I'm not complaining,
merely noticing.)
--
You received this message because you are sub
Hi,
Is it okay to use syscall.Mmap to allocate large amounts of memory, or
will it conflict with Go's memory allocator?
-- Juliusz
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it,
> unlike net.Dialer, there is no DialContext method for proxy.Dialer.
That turns out to be issue #19354.
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to golang-n
Hi,
I'm using golang.org/x/net/proxy, and I've run into an issue: there
appears to be no way to cancel a (*proxy.Dialer).Dial in progress --
unlike net.Dialer, there is no DialContext method for proxy.Dialer.
Any idea for a workaround?
(By the way, since net.Dial is a struct, not an interface, m
> Which version of Go are you using?
1.9.3.
> https://github.com/golang/go/blob/master/src/net/pipe.go#L224
Excellent, thanks.
(In case anyone is interested -- wrapping net.Pipe in order to avoid the
errors took all of five minutes.)
--
You received this message because you are subscribed to
In net/pipe.go, there's this code:
func (p *pipe) SetReadDeadline(t time.Time) error {
return &OpError{...}
}
This breaks my code, which uses timeouts and dutifully checks for
errors.
I guess I have three solutions:
1. remove the error checking in my code;
2. wrap net.Pi
> I was meant to be a successful C++/Java programmer, now that is ruined
> forever.
[...]
> My life is ruined and it's on you.
You can only blame yourself. You should have studied for the exam
rather than doing extra-curricular stuff.
--
You received this message because you are subscribed t
> It depends entirely on your program. The simplest way to think about
> it is that the runtime imposes an overhead on the memory that your
> program allocates for its own data structures. If you think of that
> overhead as 10%, you won't be very far wrong.
How does that fit with GOGC being 100%
> It depends entirely on your program. The simplest way to think about
> it is that the runtime imposes an overhead on the memory that your
> program allocates for its own data structures. If you think of that
> overhead as 10%, you won't be very far wrong.
How does that fit with GOGC being 100%
> you need /usr/local/go/lib/time/zoneinfo.zip. time.LoadLocation is using
> it. Also /usr/local/go/lib/time/ has a script to refresh timezones.
It turns out that copying /etc/localtime into the chroot was enough.
Thanks to the person who helped me by private mail (he'll know who he
is).
-- Juli
Hi,
I'm running a statically linked (CGO_ENABLED=0) Go network server in
a chroot under Linux. The chroot is completely empty (except for the
server's data files), yet, to my surprise, the only issue I'm seeing is
that the timezone is wrong.
So two questions, perhaps three:
1. Which file(s) d
I'm probably missing something obvious, but I've looked through the
standard library to no avail. How do I sanitise a []byte to make sure
it's a UTF-8 string by replacing all incorrect sequences by the
replacement character (or whatever)?
I've found unicode/utf8.Valid, which tells me if a []byte
> I have started to use non pointer slices much more as of late.
> Every time I bother measuring it is always faster and it is better for the
> GC (usually, caveats apply).
So do I. I was just pointing out a caveat that tripped me a couple times.
> It also, perhaps naively, feels safer... :)
No
>> What size of T affects is appending/inserting/deleting items to/from
>> the slice. If one passes around a value of type []T, those operations
>> are probably performed on the value.
> On the flip side, []*T will be less cache/TLB/GC friendly than
> []T, unless T is much larger than a ptr.
On t
> I guess I dont understand why you would want the lock entirely for the
> entire execution of the function until the defer.
You can get the effect of block-scoped defers by using a local anonymous
function:
func f(a *A) {
func() {
a.mu.Lock()
defer a.mu.Lock(
This is not Go-specific, I hope I'm not breaking some unwritten rule by
replying.
> I just figured this out. I need to manually set the NIC to promiscuous
> mode.
> Now the question is, is there a way to set the NIC to promiscuous mode
> in code, like in pcap.openlive?
You want to call sysctl(
> What you are doing is what sync.Once was invented for:
Uh-huh. Once is similar but slightly more primitive than a future,
since the thunk is passed explicitly to the Do() method instead of being
stored in the future itself.
> https://play.golang.org/p/erZqwFYgIR
I think there's a bug in your
> Depends on what your profiling is telling you.
The trouble is -- I have no idea what is the impact of small allocations.
I've managed to eliminate most useless large allocations (the amount of
data consed used to be twice the amount of data processed, it's now on
the order of 103%), which has ha
> A method value, on the other hand, will allocate memory in some cases,
> as it may need to hold a copy of the value whose method will be
> invoked.
Even if the method takes a pointer receiver?
-- Juliusz
--
You received this message because you are subscribed to the Google Groups
"golang-nut
> The answer depends on whether you have just one value or many. For a single
> value (sometimes known as a "future"), I tend to pair a chan of struct{}
> with a value to be set. To make the value available, set it, then close the
> channel. Readers wait on the channel, then read the value.
That's
I was about to do something like that:
var p *P
...
otherpackage.f(func(data []byte) {
a := p.x + p.y * 42 + p.someothercomplicatedstuff
p.g(data, a)
}
(Yeah, I know. I dislike callbacks too, but I'm pretty much stuck in
this particular case since Go doesn't do
> 1. "defer go" extend defers to work on goroutine exit with mechanism just
> like defer, but if we say "defer go f()"
> instead of "defer f()" then we run on goroutine exit. Very big gains for
> scaling here IMHO.
If I read the language specification right, goroutines have no identity:
a gor
Hi,
I've got a CPU-bound function that is not called very frequently, and
hence doesn't appear prominently in the CPU profile, but I'm guessing
that it takes a significant time to run (on the order of tens of
milliseconds), and hence increases the latency of the calling goroutine.
I don't see any
> Hmm maybe I misunderstood your use case. I thought you were basically
> setting a fixed write duration via SetWriteDeadline() before each Write()
> call, in which case the same treatment probably should be done for Flush().
I'm already doing that.
--
You received this message because you are s
> Is extending the deadline right before flushing an option?
No. Before the Flush (or the Write) times out, I don't know that this
particular peer is congested, and hence I have no reason to reschedule
requests queued to this peer on a different connection.
-- Juliusz
--
You received this mess
> bufio.Writer is about 200 lines, and you probably don't even need all
> of them. Just copy it and modify it for your purposes.
Ok, thanks.
-- Juliusz
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop rec
Hi,
I've got a bufio.Writer which is wrapping a net.TCPConn. Once in
a while, Flush() will trigger a write timeout (set with SetWriteDeadline
on the underlying connection), in which case I'd like to reschedule some
requests on a different connection, and then restart the Flush() with
a more relax
> suggests you should move the wg.Add(1) out of the Goroutine from here:
[...]
> to there
Thanks, that's an actual bug.
> * Do you happen to know about the context package? It seems like a lot of
> the closedown can happen if you recast part of the system as contexts and
> cancel those explicit
> How did your students adjust to working with the GOPATH?
No issue at all. I told them to create a directory under ~/go/src, and
that was it.
> It seems to cause some people trouble.
In my experience, undergraduate students accept pretty much anything if
the instructions you give them are clea
> I glanced at babelweb2 (https://github.com/Vivena/babelweb2/). A code
> review would be useful. For example, from parser/parser.go:
Thanks for the review. As I've mentioned, neither the students nor me
had any significant experience with Go, so we were learning as we went
along.
If you happen
Dear all,
I've just finished supervising three fourth year students doing
a month-long summer project in Go. I thought some of you might be
interested in my conclusions.
The students were decent C programmers but had more experience with Java
(and I am not an experienced Go programmer myself).
>> Do I have a guarantee that the final \n will be passed to my custom
>> scan function and the result passed to the Scan function even if the
>> connection hangs just after the \n?
> Yes (assuming the underlying Reader returns the final \n).
>> Do similar properties hold for bufio.Reader (i.e.,
Hi,
I cannot find anything in the documentation about how bufio.Scanner
behaves when the underlying io.Reader does partial reads.
I'm using a Scanner to parse a stream of tokens that arrives over a TCP
socket. The stream is a sequence of lines terminated by \n. Do I have
a guarantee that the fi
67 matches
Mail list logo