sha256, AES-GCM and chacha20poly1305 allocate on every call
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 45/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- go
- Ambito
- compilers, performance
Direzione di ricerca
Start by reproducing the allocation counts with the supplied test under go test, go test -tags purego, and tinygo test; use TinyGo's -print-allocs output to locate the reported escape sites. The issue names allocation sites in crypto/sha256/sha256.go, crypto/internal/fips140/sha256/sha256.go, crypto/internal/fips140/aes/gcm/gcm_generic.go, and the x/crypto chacha files. Done means the listed TinyGo per-call allocations are reduced to match Go where feasible, with the allocation test confirming the results.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
On linux/amd64 these allocate on every call with TinyGo dev (3de4a3a8) and 0.44.0, where Go allocates nothing. Go still allocates nothing with -tags purego, so it is not the assembly.
| per call | Go | Go purego | TinyGo |
|---|---|---|---|
sha256.Sum256 |
0 | 0 | 3 |
| sha256 Reset, Write, Sum on a reused hash | 0 | 0 | 1 |
| AES-GCM Seal or Open | 0 | 0 | 6 |
| x/crypto chacha20poly1305 Seal or Open | 0 | 1 | 6 |
The counts are the same at -opt=z and -opt=2. -print-allocs names these sites.
crypto/sha256/sha256.go:59:6: object allocated on the heap: escapes at line 12
crypto/internal/fips140/sha256/sha256.go:150:10: object allocated on the heap: escapes at line 152
crypto/internal/fips140/aes/gcm/gcm_generic.go:60:19: object allocated on the heap: escapes at line 62
golang.org/x/crypto/chacha20/chacha_generic.go:76:14: object allocated on the heap: escapes at line 77
golang.org/x/crypto/chacha20poly1305/chacha20poly1305_generic.go:18:7: object allocated on the heap: escapes at unknown line
golang.org/x/crypto/chacha20poly1305/chacha20poly1305_generic.go:25:6: object allocated on the heap: escapes at unknown line
golang.org/x/crypto/chacha20poly1305/chacha20poly1305_generic.go:40:6: object allocated on the heap: escapes at unknown line
golang.org/x/crypto/chacha20poly1305/chacha20poly1305_generic.go:60:6: object allocated on the heap: escapes at unknown line
Most are small local arrays or a value from a constructor such as sha256.New or chacha20.NewUnauthenticatedCipher, which Go keeps on the stack. They sit on the per packet path of anything doing TLS or Noise. We found them profiling a large network server built with TinyGo, where they were a large share of its allocation rate.
Test
package allocpar
import (
"crypto/aes"
"crypto/cipher"
"crypto/sha256"
"testing"
"time"
"golang.org/x/crypto/chacha20poly1305"
)
var sink [32]byte
func report(t *testing.T, name string, f func()) {
t.Helper()
t.Logf("%-28s %.1f allocs/op", name, testing.AllocsPerRun(200, f))
}
func TestAllocs(t *testing.T) {
data := make([]byte, 1400)
report(t, "sha256.Sum256", func() { sink = sha256.Sum256(data) })
h := sha256.New()
report(t, "sha256 Reset+Write+Sum", func() {
h.Reset()
h.Write(data)
h.Sum(sink[:0])
})
key := make([]byte, 32)
aead, err := chacha20poly1305.New(key)
if err != nil {
t.Fatal(err)
}
nonce := make([]byte, aead.NonceSize())
sealed := make([]byte, 0, len(data)+aead.Overhead())
opened := make([]byte, 0, len(data))
report(t, "chacha20poly1305 Seal", func() { sealed = aead.Seal(sealed[:0], nonce, data, nil) })
report(t, "chacha20poly1305 Open", func() { opened, _ = aead.Open(opened[:0], nonce, sealed, nil) })
block, _ := aes.NewCipher(key)
gcm, _ := cipher.NewGCM(block)
gnonce := make([]byte, gcm.NonceSize())
report(t, "AES-GCM Seal", func() { sealed = gcm.Seal(sealed[:0], gnonce, data, nil) })
report(t, "AES-GCM Open", func() { opened, _ = gcm.Open(opened[:0], gnonce, sealed, nil) })
tm := time.NewTimer(time.Hour)
report(t, "Timer.Reset", func() { tm.Reset(time.Hour) })
tm.Stop()
}
Run with go test -v, go test -tags purego -v and tinygo test -v.
- Lingua principale
- Go
- Stelle
- 17.8k
- Fork
- 1.1k
- Merge medio
- 1g 4h
- PR unite (30g)
- 380
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di tinygo-org/tinygo
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
tinygo-org/tinygo#6727 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 86/100
tinygo-org/tinygo#6711 ·
I maintainer di solito rispondono entro 1 giorno
-
Builds are not reproducible: cgo snippet paths in debug infoForse già presa @tridev-tej l’ha presa 1 giorno fa. Apertaenhancement good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
tinygo-org/tinygo#6619 ·
I maintainer di solito rispondono entro 1 giorno
-
Fix the targets that tinygo build -target rejectsForse già presa @narguis l’ha presa 2 giorni fa. Apertabug good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
tinygo-org/tinygo#6617 · 5 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 62/100
tinygo-org/tinygo#6312 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di tinygo-org/tinygo
Issue simili
-
release
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 75/100
github/gh-aw-mcpg#17603 ·
I maintainer di solito rispondono entro 1 giorno
-
help wanted
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 94/100
oras-project/oras-go#1827 ·
I maintainer di solito rispondono entro 1 giorno
-
docs: database/sql Sessions example never commits its batch, and its "Full Example" link is a 404Apertadocumentation
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
ClickHouse/clickhouse-go#2185 ·
I maintainer di solito rispondono entro 1 giorno
-
bug needs triage receiver/podman
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
open-telemetry/opentelemetry-collector-contrib#53700 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
tagvalue.Read fails with "token too long" on lines over 64 KiBForse già presa @G26karthik l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
spdx/tools-golang#319 ·