mirror of https://github.com/v2ray/v2ray-core
remove 8k buffer pool
parent
f506a39d32
commit
b1dfff2fdd
|
@ -181,11 +181,6 @@ func New() *Buffer {
|
|||
return mediumPool.Allocate()
|
||||
}
|
||||
|
||||
// NewSmall returns a buffer with 0 length and 2K capacity.
|
||||
func NewSmall() *Buffer {
|
||||
return smallPool.Allocate()
|
||||
}
|
||||
|
||||
// NewLocal creates and returns a buffer with 0 length and given capacity on current thread.
|
||||
func NewLocal(size int) *Buffer {
|
||||
return &Buffer{
|
||||
|
|
|
@ -96,16 +96,13 @@ func (p *BufferPool) Free(buffer *Buffer) {
|
|||
|
||||
const (
|
||||
// Size of a regular buffer.
|
||||
Size = 8 * 1024
|
||||
// SizeSmall is the size of a small buffer.
|
||||
SizeSmall = 2 * 1024
|
||||
Size = 2 * 1024
|
||||
|
||||
poolSizeEnvKey = "v2ray.buffer.size"
|
||||
)
|
||||
|
||||
var (
|
||||
mediumPool Pool
|
||||
smallPool = NewSyncPool(SizeSmall)
|
||||
)
|
||||
|
||||
func getDefaultPoolSize() uint32 {
|
||||
|
|
|
@ -67,39 +67,3 @@ func BenchmarkNewLocalBuffer8192(b *testing.B) {
|
|||
buffer.Release()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkNewBuffer2048(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
buffer := NewSmall()
|
||||
buffer.Release()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkNewLocalBuffer2048(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
buffer := NewLocal(2048)
|
||||
buffer.Release()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkBufferValue(b *testing.B) {
|
||||
x := Buffer{}
|
||||
doSomething := func(a Buffer) {
|
||||
_ = a.Len()
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
doSomething(x)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkBufferPointer(b *testing.B) {
|
||||
x := NewSmall()
|
||||
doSomething := func(a *Buffer) {
|
||||
_ = a.Len()
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
doSomething(x)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -246,7 +246,7 @@ func EncodeUDPPacket(request *protocol.RequestHeader, payload *buf.Buffer) (*buf
|
|||
}
|
||||
account := rawAccount.(*ShadowsocksAccount)
|
||||
|
||||
buffer := buf.NewSmall()
|
||||
buffer := buf.New()
|
||||
ivLen := account.Cipher.IVSize()
|
||||
buffer.AppendSupplier(buf.ReadFullFrom(rand.Reader, ivLen))
|
||||
iv := buffer.Bytes()
|
||||
|
@ -363,7 +363,7 @@ type UDPReader struct {
|
|||
}
|
||||
|
||||
func (v *UDPReader) Read() (buf.MultiBuffer, error) {
|
||||
buffer := buf.NewSmall()
|
||||
buffer := buf.New()
|
||||
err := buffer.AppendSupplier(buf.ReadFrom(v.Reader))
|
||||
if err != nil {
|
||||
buffer.Release()
|
||||
|
|
|
@ -332,7 +332,7 @@ func DecodeUDPPacket(packet []byte) (*protocol.RequestHeader, []byte, error) {
|
|||
}
|
||||
|
||||
func EncodeUDPPacket(request *protocol.RequestHeader, data []byte) *buf.Buffer {
|
||||
b := buf.NewSmall()
|
||||
b := buf.New()
|
||||
b.AppendBytes(0, 0, 0 /* Fragment */)
|
||||
appendAddress(b, request.Address, request.Port)
|
||||
b.Append(data)
|
||||
|
@ -348,7 +348,7 @@ func NewUDPReader(reader io.Reader) *UDPReader {
|
|||
}
|
||||
|
||||
func (r *UDPReader) Read() (buf.MultiBuffer, error) {
|
||||
b := buf.NewSmall()
|
||||
b := buf.New()
|
||||
if err := b.AppendSupplier(buf.ReadFrom(r.reader)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -181,7 +181,7 @@ func (v *Server) handleUDPPayload(ctx context.Context, conn internet.Connection,
|
|||
log.Access(source, request.Destination, log.AccessAccepted, "")
|
||||
}
|
||||
|
||||
dataBuf := buf.NewSmall()
|
||||
dataBuf := buf.New()
|
||||
dataBuf.Append(data)
|
||||
udpServer.Dispatch(ctx, request.Destination(), dataBuf, func(payload *buf.Buffer) {
|
||||
defer payload.Release()
|
||||
|
|
|
@ -53,7 +53,7 @@ type HeaderReader struct {
|
|||
}
|
||||
|
||||
func (*HeaderReader) Read(reader io.Reader) (*buf.Buffer, error) {
|
||||
buffer := buf.NewSmall()
|
||||
buffer := buf.New()
|
||||
totalBytes := 0
|
||||
endingDetected := false
|
||||
for totalBytes < maxHeaderLength {
|
||||
|
@ -169,7 +169,7 @@ func (c *HttpConn) Close() error {
|
|||
}
|
||||
|
||||
func formResponseHeader(config *ResponseConfig) *HeaderWriter {
|
||||
header := buf.NewSmall()
|
||||
header := buf.New()
|
||||
header.AppendSupplier(serial.WriteString(strings.Join([]string{config.GetFullVersion(), config.GetStatusValue().Code, config.GetStatusValue().Reason}, " ")))
|
||||
header.AppendSupplier(writeCRLF)
|
||||
|
||||
|
@ -194,7 +194,7 @@ type HttpAuthenticator struct {
|
|||
}
|
||||
|
||||
func (a HttpAuthenticator) GetClientWriter() *HeaderWriter {
|
||||
header := buf.NewSmall()
|
||||
header := buf.New()
|
||||
config := a.config.Request
|
||||
header.AppendSupplier(serial.WriteString(strings.Join([]string{config.GetMethodValue(), config.PickUri(), config.GetFullVersion()}, " ")))
|
||||
header.AppendSupplier(writeCRLF)
|
||||
|
|
|
@ -81,7 +81,7 @@ func (c *ClientConnection) ResetSecurity(header internet.PacketHeader, security
|
|||
}
|
||||
|
||||
func (c *ClientConnection) Run() {
|
||||
payload := buf.NewSmall()
|
||||
payload := buf.New()
|
||||
defer payload.Release()
|
||||
|
||||
for {
|
||||
|
|
|
@ -20,7 +20,7 @@ type SimpleSegmentWriter struct {
|
|||
func NewSegmentWriter(writer io.Writer) SegmentWriter {
|
||||
return &SimpleSegmentWriter{
|
||||
writer: writer,
|
||||
buffer: buf.NewSmall(),
|
||||
buffer: buf.New(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ func (v *DataSegment) Command() Command {
|
|||
|
||||
func (v *DataSegment) SetData(data []byte) {
|
||||
if v.Data == nil {
|
||||
v.Data = buf.NewSmall()
|
||||
v.Data = buf.New()
|
||||
}
|
||||
v.Data.Reset(func(b []byte) (int, error) {
|
||||
return copy(b, data), nil
|
||||
|
|
|
@ -136,7 +136,7 @@ L:
|
|||
default:
|
||||
}
|
||||
|
||||
buffer := buf.NewSmall()
|
||||
buffer := buf.New()
|
||||
var noob int
|
||||
var addr *net.UDPAddr
|
||||
err := buffer.AppendSupplier(func(b []byte) (int, error) {
|
||||
|
|
Loading…
Reference in New Issue