High init costs
moorereason opened this issue · 1 comments
moorereason commented
While testing the new init cost debugging output in go 1.16, I found that emoji has one of the higher memory init costs in Hugo's dependencies.
An an example, these are the init costs while running hugo version
(which doesn't call into emoji):
$ GODEBUG=inittrace=1 go run . version 2>&1 | rg emoji
init github.com/kyokomi/emoji @15 ms, 3.9 ms clock, 783480 bytes, 3093 allocs
By deferring the emojiMap population until needed, emoji's init costs can be greatly reduced:
$ GODEBUG=inittrace=1 go run . version 2>&1 | rg emoji
init github.com/kyokomi/emoji @21 ms, 0.009 ms clock, 2824 bytes, 30 allocs
I have a branch with these changes. I can submit a PR if you're interested.
kyokomi commented
Thanks for the issue, @moorereason.
#49 I used sync.Once to initialize the codeMap on the first use.