Skip to content
This repository has been archived by the owner on Apr 9, 2020. It is now read-only.

Performance improvement, avoid create new slice for each Read #460

Open
ghost opened this issue Jan 22, 2019 · 1 comment
Open

Performance improvement, avoid create new slice for each Read #460

ghost opened this issue Jan 22, 2019 · 1 comment

Comments

@ghost
Copy link

ghost commented Jan 22, 2019

cipherData = make([]byte, len(b))

103.60MB   103.60MB (flat, cum) 88.15% of Total
         .          .    104:           }
         .          .    105:   }
         .          .    106:
         .          .    107:   cipherData := c.readBuf
         .          .    108:   if len(b) > len(cipherData) {
  103.60MB   103.60MB    109:           cipherData = make([]byte, len(b))
         .          .    110:   } else {
         .          .    111:           cipherData = cipherData[:len(b)]
         .          .    112:   }
         .          .    113:
         .          .    114:   n, err = c.Conn.Read(cipherData)
(pprof) 

avoid create new slice for each Read().

	cipherData := c.readBuf
	if len(b) < len(cipherData) {
		cipherData = cipherData[:len(b)]
	}
@arthurkiller
Copy link
Collaborator

arthurkiller commented Jan 22, 2019 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant