Slawomir Pryczek
unread,Jun 14, 2026, 4:57:41 AM (4 days ago) Jun 14Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to golang-nuts
Hey guys,
I have a generic function:
func GetParam[T string | int | float64 | json.Number](pp ParsedParams, key string) (T, bool) {
var zero T
...
switch any(zero).(type) {
It's a simple helper to get a value from a union-like struct. However, I've been told that the any(zero).(type) call causes a heap allocation on every invocation — is that a significant performance concern when the function is called several thousand times per second? Would it be better to replace it with four separate typed functions? Is there some better way?
Thanks