| Feature | Description |
|---|---|
values |
A package for working with values. |
values.IsZero |
A function that checks if a value is zero. |
values.Pick |
A function that picks a value from a map. |
values.PickHasValue |
A function that picks a value from a list of values. |
values.PickHasValue |
A function that picks a value from a list of values. |
IsZero checks if a value is zero and accepts all types.
- Type Switch (Current - for handled types):
- ~0.5-2 nanoseconds - Compiles to efficient jump tables
- Extremely fast, direct comparisons
- No heap allocations
- Reflection Approach:
- ~5-15 nanoseconds - Modern Go has optimized reflect.Value.IsZero()
- Still very fast for most use cases
- Correct for ALL types automatically
- Real-World Impact:
- 3-10x slower with reflection, but we're talking nanoseconds
- Unless you're calling IsZero millions of times in tight loops, the difference is negligible
- Correctness trumps micro-optimization
Why Hybrid is Better:
- 90%+ of use cases hit the fast type-switch path
- 100% correctness for edge cases via reflection fallback
- Maintainable - no need to manually handle every possible type
- Performance where it matters - common types stay fast
Pick picks a value from a map.