#high usage of runtime.memmove in top10 (pprof)

38 messages · Page 1 of 1 (latest)

bold dawn
#

yes

#

do the buf := before the loop

#

and use strings.Builder or bytes.Buffer instead of buffer +=

#

or it will make a lot of unused strings

#

And you have to improve the strings.Contains

#

to lower the CPU usage

#

wdym

#

yes

#

it will write the buf again

remote sorrelBOT
#

    type Reader interface {
	Read(p []byte) (n int, err error)
}

Reader is the interface that wraps the basic Read method....

More documentation omitted

bold dawn
#

no it won't, it will write from the start of the slice

leaden sage
bold dawn
#

it will replace all the data that avaliable (n)

#

so if your slice is [0 0 0 1], and the data avaliable is [2], then you slice will be [2 0 0 1] or [2 1 2 3] we don't know, the only thing Read can promise to you is correct is buf[:n]

#

so you have to fix your code

#

not use buf but buf[:n]

#

This won't close

#

But if it's inactive for one day, then it will be mark as stale

#

you can ping me if you want get help

#

Note that when it's marked as stale, you can still send messages

brazen ore
#

yea - so I'd say string concat was the issue

bold dawn
#

sometimes, but not always

#

depends on the sender

brazen ore
#

maybe, but reallocation itself doesn't cause memmove afaik

bold dawn
#

I'll say that 1024 is a little bit low, your computer can handle 1MB really well

#

But depends on your sender, if you send piece messages, then lower buffer works

#

It's 128KB, maybe yeah

brazen ore
#

also I always start with something from 1024 to 4096
the latter is what bufio does

bold dawn
#

hm what's the point to use readUntil for http requests

#

looks like XY problem

#

You should use scanner for http request, it should be read line by line until a empty line

#

so bufio.Reader is your best choice maybe

remote sorrelBOT
bold dawn
remote sorrelBOT
#

      func (b *Reader) ReadLine() (line []byte, isPrefix bool, err error)
    ```
ReadLine is a low-level line-reading primitive. Most callers should use ReadBytes('\n') or ReadString('\n') instead or use a Scanner....

*More documentation omitted*
bold dawn
#

I'll go sleep now anyways, will check tomorrow