Re: [go-nuts] Re: slices grow at 25% after 1024 but why 1024?

2021-09-08 Thread Arnaud Delobelle
Nice! Arnaud On Tue, 7 Sep 2021, 18:02 Keith Randall, wrote: > Sounds good. CL up for review at > https://go-review.googlesource.com/c/go/+/347917 > > On Mon, Sep 6, 2021 at 7:30 PM Arnaud Delobelle wrote: > >> If the growing function is currently >> >> f(x) = 2x for x < 1024 >> f(x) =

Re: [go-nuts] Re: slices grow at 25% after 1024 but why 1024?

2021-09-07 Thread 'Keith Randall' via golang-nuts
Sounds good. CL up for review at https://go-review.googlesource.com/c/go/+/347917 On Mon, Sep 6, 2021 at 7:30 PM Arnaud Delobelle wrote: > If the growing function is currently > > f(x) = 2x for x < 1024 > f(x) = x + x/4 otherwise > > (Which I haven't checked), couldn't a simple way be to

Re: [go-nuts] Re: slices grow at 25% after 1024 but why 1024?

2021-09-06 Thread Arnaud Delobelle
If the growing function is currently f(x) = 2x for x < 1024 f(x) = x + x/4 otherwise (Which I haven't checked), couldn't a simple way be to use e.g. f(x) = 2xfor x < 1024 f(x) = x + x/4 + 768 otherwise Then f(1023) = 2046 f(1024) = 2048 So the function is monotonic

Re: [go-nuts] Re: slices grow at 25% after 1024 but why 1024?

2021-09-06 Thread 'Keith Randall' via golang-nuts
I don't think this is an important thing to fix, but I agree it is a bit odd. If there's a simple way to restore monotonicity we'll consider it. A similar issue: https://github.com/golang/go/issues/41239 On Sunday, September 5, 2021 at 8:59:01 AM UTC-7 jake...@gmail.com wrote: > You are 100% cor

Re: [go-nuts] Re: slices grow at 25% after 1024 but why 1024?

2021-09-05 Thread jake...@gmail.com
You are 100% correct. I missed that value. oops On Sunday, September 5, 2021 at 10:16:08 AM UTC-4 arn...@gmail.com wrote: > > > On Sun, 5 Sep 2021, 14:59 jake...@gmail.com, wrote: > [...] > >> In the example given (https://play.golang.org/p/RJbEkmFsPKM >>

Re: [go-nuts] Re: slices grow at 25% after 1024 but why 1024?

2021-09-05 Thread Jesper Louis Andersen
On Sun, Sep 5, 2021 at 3:59 PM jake...@gmail.com wrote: > Like Brian, I think part of he problem is possibly a miscommunication > based on "monotonically increasing". The term means that each point is > greater than, *or equal to*, the previous one. > https://en.wikipedia.org/wiki/Monotonic_funct

Re: [go-nuts] Re: slices grow at 25% after 1024 but why 1024?

2021-09-05 Thread Arnaud Delobelle
On Sun, 5 Sep 2021, 14:59 jake...@gmail.com, wrote: [...] > In the example given (https://play.golang.org/p/RJbEkmFsPKM > ), the capacities *are *"monotonically > increasing", as no number in the second column is smaller than the one > before it. > Nitpick

Re: [go-nuts] Re: slices grow at 25% after 1024 but why 1024?

2021-09-05 Thread jake...@gmail.com
Like Brian, I think part of he problem is possibly a miscommunication based on "monotonically increasing". The term means that each point is greater than, *or equal to*, the previous one. https://en.wikipedia.org/wiki/Monotonic_function. In other words, it never decreases. In the example given

Re: [go-nuts] Re: slices grow at 25% after 1024 but why 1024?

2021-09-05 Thread Brian Candler
Ah I see. In particular, if you have a slice whose len and cap are both 1000, the new cap is 2048; but if you have a slice whose len and cap are both 1100, then the new cap is 1408. I don't see that as a problem in any shape or form. All that's required is: (1) New cap is at least as large as

Re: [go-nuts] Re: slices grow at 25% after 1024 but why 1024?

2021-09-05 Thread 'Dan Kortschak' via golang-nuts
On Sun, 2021-09-05 at 03:51 -0700, Brian Candler wrote: > I'm not sure you're clear about what "monotonically increasing" > means. > > Are you saying that there are some cases where append() results in > the allocated size of a slice *shrinking*? If so, please > demonstrate. I think he means that

Re: [go-nuts] Re: slices grow at 25% after 1024 but why 1024?

2021-09-05 Thread Brian Candler
I'm not sure you're clear about what "monotonically increasing" means. Are you saying that there are some cases where append() results in the allocated size of a slice *shrinking*? If so, please demonstrate. -- You received this message because you are subscribed to the Google Groups "golang-

Re: [go-nuts] Re: slices grow at 25% after 1024 but why 1024?

2021-09-05 Thread tapi...@gmail.com
On Sunday, September 5, 2021 at 2:26:23 AM UTC-4 axel.wa...@googlemail.com wrote: > On Sun, Sep 5, 2021 at 7:02 AM tapi...@gmail.com > wrote: > >> >> >> On Sunday, September 5, 2021 at 12:52:06 AM UTC-4 Kurtis Rader wrote: >> >>> On Sat, Sep 4, 2021 at 9:38 PM tapi...@gmail.com >>> wrote: >

Re: [go-nuts] Re: slices grow at 25% after 1024 but why 1024?

2021-09-04 Thread 'Axel Wagner' via golang-nuts
On Sun, Sep 5, 2021 at 7:02 AM tapi...@gmail.com wrote: > > > On Sunday, September 5, 2021 at 12:52:06 AM UTC-4 Kurtis Rader wrote: > >> On Sat, Sep 4, 2021 at 9:38 PM tapi...@gmail.com >> wrote: >> >>> Why? That is an undocumented implementation detail. Furthermore, the length of "x1" and

Re: [go-nuts] Re: slices grow at 25% after 1024 but why 1024?

2021-09-04 Thread tapi...@gmail.com
On Sunday, September 5, 2021 at 12:52:06 AM UTC-4 Kurtis Rader wrote: > On Sat, Sep 4, 2021 at 9:38 PM tapi...@gmail.com > wrote: > >> Why? That is an undocumented implementation detail. Furthermore, the >>> length of "x1" and "x2" at the time when they are appended to, in >>> combination wi

Re: [go-nuts] Re: slices grow at 25% after 1024 but why 1024?

2021-09-04 Thread Kurtis Rader
On Sat, Sep 4, 2021 at 9:38 PM tapi...@gmail.com wrote: > Why? That is an undocumented implementation detail. Furthermore, the >> length of "x1" and "x2" at the time when they are appended to, in >> combination with the value being appended, are reasonable predictors of the >> capacity of the new

Re: [go-nuts] Re: slices grow at 25% after 1024 but why 1024?

2021-09-04 Thread tapi...@gmail.com
On Sunday, September 5, 2021 at 12:12:46 AM UTC-4 Kurtis Rader wrote: > On Sat, Sep 4, 2021 at 8:57 PM tapi...@gmail.com > wrote: > >> On Saturday, September 4, 2021 at 11:50:17 PM UTC-4 Kurtis Rader wrote: >> >>> On Sat, Sep 4, 2021 at 8:39 PM tapi...@gmail.com >>> wrote: >>> The probl

Re: [go-nuts] Re: slices grow at 25% after 1024 but why 1024?

2021-09-04 Thread tapi...@gmail.com
On Sunday, September 5, 2021 at 12:16:48 AM UTC-4 kortschak wrote: > This is what you're describing, right? > https://play.golang.org/p/RJbEkmFsPKM > > The code that does this is here > > https://github.com/golang/go/blob/9133245be7365c23fcd60e3bb60ebb614970cdab/src/runtime/slice.go#L183-L242

Re: [go-nuts] Re: slices grow at 25% after 1024 but why 1024?

2021-09-04 Thread 'Dan Kortschak' via golang-nuts
This is what you're describing, right? https://play.golang.org/p/RJbEkmFsPKM The code that does this is here https://github.com/golang/go/blob/9133245be7365c23fcd60e3bb60ebb614970cdab/src/runtime/slice.go#L183-L242 . Note that there are cap adjustments to optimise block sizes and alignments. This

Re: [go-nuts] Re: slices grow at 25% after 1024 but why 1024?

2021-09-04 Thread Kurtis Rader
On Sat, Sep 4, 2021 at 8:57 PM tapi...@gmail.com wrote: > On Saturday, September 4, 2021 at 11:50:17 PM UTC-4 Kurtis Rader wrote: > >> On Sat, Sep 4, 2021 at 8:39 PM tapi...@gmail.com >> wrote: >> >>> The problem of the current algorithm is it is not monotonically >>> increasing: >>> >> >> Pleas

Re: [go-nuts] Re: slices grow at 25% after 1024 but why 1024?

2021-09-04 Thread tapi...@gmail.com
On Saturday, September 4, 2021 at 11:50:17 PM UTC-4 Kurtis Rader wrote: > On Sat, Sep 4, 2021 at 8:39 PM tapi...@gmail.com > wrote: > >> The problem of the current algorithm is it is not monotonically >> increasing: >> > > Please explain why that is a problem. Also, I think you are > misusin

Re: [go-nuts] Re: slices grow at 25% after 1024 but why 1024?

2021-09-04 Thread Kurtis Rader
On Sat, Sep 4, 2021 at 8:39 PM tapi...@gmail.com wrote: > The problem of the current algorithm is it is not monotonically increasing: > Please explain why that is a problem. Also, I think you are misusing "monotonically increasing". The behavior up to length 1024 is not "monotonically increasing