interp: raise the default loop limit to 2048
I maintainer di solito rispondono entro 1 giorno
@davecheney ci sta già lavorando.
Dal 27/10/2026.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
interp stops evaluating a function when any basic block is entered more than 1000 times in one call (interp.DefaultMaxInterpBlockEntries, -interp-loop-limit). The init then runs at runtime instead of becoming data in the binary.
The value of 1000 was chosen in #5395, whose description said "Perhaps this is a bad idea (1000 is random), but it does seem to fix the problem?". That PR measured compile times for the #2090 reproducer, a map filled with tens of thousands of strconv.Itoa keys.
Ordinary lookup tables in TinyGo programs can exceed it.
A CRC-8 table built in init, the usual way:
var crc8Table = makeCRC8Table()
func makeCRC8Table() [256]uint8 {
var table [256]uint8
for i := range table {
crc := uint8(i)
for range 8 {
if crc&0x80 != 0 {
crc = crc<<1 ^ 0x07
} else {
crc <<= 1
}
}
table[i] = crc
}
return table
}
The inner loop body runs 256 × 8 = 2048 times, so the table is computed at startup and lives in RAM. It needs -interp-loop-limit=2048. CRC-16 (0x1021) and CRC-32 (0xEDB88320) tables built the same way also need exactly 2048. In a program with a few other typical inits, on cortex-m-qemu at -opt=z, raising the limit to 2048 shrinks code from 30272 to 29568 bytes and RAM from 4696 to 4440 bytes, with no change in build time.
The RP2 PLL divider table hit the same limit. df440ec8 split genTable into genTableEntry purely to keep each call under 1000 entries, and left a comment explaining why. In its original nested form it needs a limit of 1715.
Build times on cortex-m-qemu at -opt=z, best of three with a warm cache per limit:
| program | limit 1000 | no limit |
|---|---|---|
| program with a CRC-8 table and other typical inits | 0.49s | 0.48s |
fill [20000]uint32 with a multiply |
0.28s | 0.28s |
| #2090 map, 5,000 entries | 0.58s | 1.78s |
| #2090 map, 20,000 entries | 0.57s | 10.93s |
The expensive case is map mutation, where interp clones memory on each update. Plain loops cost nothing measurable at these sizes.
Raising the interp limit would permit common table building code to be moved to compile time, without restructuring it to fit the limit as the PLL code was.
I propose raising the default to 2048. That covers a 256 entry table built bit by bit, which includes CRC-8, CRC-16 and CRC-32, and the original PLL table. It keeps a bound on the #2090 case:
| program | limit 1000 | limit 2048 |
|---|---|---|
| #2090 map, 2,000 entries | 0.59s | 0.88s |
| #2090 map, 5,000 entries | 0.58s | 0.89s |
| #2090 map, 20,000 entries | 0.57s | 0.89s |
With the limit at 2048, df440ec8 can be reverted so genTable is written as a plain nested loop again. //go:noruntime on calcPLLDivs (75f5eb0b) backstops it. If the table ever falls back to runtime, the build fails with //go:noruntime function machine.calcPLLDivs is used at runtime by machine.init#2.
The limit counts block entries, which treats every block as costing the same. One step of a CRC loop counts the same as a map insertion, although the map insertion is far more expensive for interp to evaluate.
- 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 ·