Closed deadprogram closed 1 year ago
Additional benefit: binaries are slightly smaller as well :smile_cat:
I will check on it this weekend.
before:
sago3@B450GT3 MINGW64 ~/dev/src/tinygo.org/x/tinyfont (dev)
$ tinygo flash --target wioterminal --size short --print-allocs . ./examples/displays/
go: downloading tinygo.org/x/drivers v0.24.0
C:\Users\sago3\dev\pkg\mod\tinygo.org\x\drivers@v0.24.0\ili9341\spi_atsamd51.go:20:21: object allocated on the heap: escapes at line 20
C:\Users\sago3\dev\pkg\mod\tinygo.org\x\drivers@v0.24.0\ili9341\spi_atsamd51.go:15:16: object allocated on the heap: escapes at line 15
C:\Users\sago3\dev\src\tinygo.org\x\tinyfont\display.go:17:24: object allocated on the heap: escapes at line 17
C:\Users\sago3\dev\src\tinygo.org\x\tinyfont\concrete.go:100:20: object allocated on the heap: escapes at unknown line
C:\Users\sago3\dev\src\tinygo.org\x\tinyfont\concrete.go:97:10: object allocated on the heap: escapes at unknown line
C:\Users\sago3\dev\src\tinygo.org\x\tinyfont\concrete.go:95:20: object allocated on the heap: escapes at line 95
C:\Users\sago3\dev\src\tinygo.org\x\tinyfont\concrete.go:57:19: object allocated on the heap: escapes at line 57
C:\tinygo\tinygo\src\runtime\string.go:124:14: object allocated on the heap: size is not constant
C:\tinygo\tinygo\src\runtime\baremetal.go:41:14: object allocated on the heap: size is not constant
C:\tinygo\tinygo\src\runtime\slice.go:30:15: object allocated on the heap: size is not constant
C:\go\src\errors\errors.go:59:21: object allocated on the heap: escapes at line 59
C:\tinygo\tinygo\src\internal\task\task_stack.go:75:24: object allocated on the heap: size is not constant
C:\tinygo\tinygo\src\internal\task\task_stack.go:113:12: object allocated on the heap: escapes at line 115
code data bss | flash ram
12704 31364 6680 | 44068 38044
after:
sago3@B450GT3 MINGW64 ~/dev/src/tinygo.org/x/tinyfont (no-heap-alloc)
$ tinygo flash --target wioterminal --size short --print-allocs . ./examples/displays/
C:\Users\sago3\dev\pkg\mod\tinygo.org\x\drivers@v0.24.0\ili9341\spi_atsamd51.go:20:21: object allocated on the heap: escapes at line 20
C:\Users\sago3\dev\pkg\mod\tinygo.org\x\drivers@v0.24.0\ili9341\spi_atsamd51.go:15:16: object allocated on the heap: escapes at line 15
C:\Users\sago3\dev\src\tinygo.org\x\tinyfont\concrete.go:95:20: object allocated on the heap: escapes at line 95
C:\tinygo\tinygo\src\runtime\string.go:124:14: object allocated on the heap: size is not constant
C:\tinygo\tinygo\src\runtime\baremetal.go:41:14: object allocated on the heap: size is not constant
C:\tinygo\tinygo\src\runtime\slice.go:30:15: object allocated on the heap: size is not constant
C:\go\src\errors\errors.go:59:21: object allocated on the heap: escapes at line 59
C:\tinygo\tinygo\src\internal\task\task_stack.go:75:24: object allocated on the heap: size is not constant
C:\tinygo\tinygo\src\internal\task\task_stack.go:113:12: object allocated on the heap: escapes at line 115
code data bss | flash ram
12532 31364 6680 | 43896 38044
@sago35 I just modified GetGlyph
as you suggested and force pushed this branch.
Turns out there were some additional allocations that were a problem in interrupts in the WriteLineColorsRotated()
and LineWidth()
functions, but they were relatively easy to take care of.
I think this PR is now ready.
Merging, thanks @sago35 and @aykevl for review.
This PR modifies TinyFont to avoid all heap allocations, so that it can be called safely from within interrupt handlers.
It also includes a commit to fix the
Makefile
so runningmake
by itself works as expected.