Commit Graph
8 Commits
Author SHA1 Message Date
J. Nick Koston f4f56cfaaa Merge remote-tracking branch 'upstream/dev' into optimize-value-accuracy
# Conflicts:
#	esphome/core/helpers.h
#	tests/components/core/test_helpers.cpp
2026-04-14 08:07:44 -10:00
J. Nick Koston cf01163c8c [core] Add uint32_to_str helper and use in preferences (#15597) 2026-04-14 07:49:44 -10:00
J. Nick Koston 2a530a4bf4 [core] Optimize format_hex_internal by splitting separator loop (#15594) 2026-04-14 07:48:33 -10:00
J. Nick Koston 3b45179948 Split uint32_to_str/frac_to_str into internal and public API
- uint32_to_str_(): raw pointer, internal use
- uint32_to_str(): template with compile-time buffer size check
- frac_to_str_(): raw pointer, internal use
- small_pow10(): simplify to ternary chain
2026-04-08 21:01:32 -10:00
J. Nick Koston e52c3b01e6 Extract buf_append_sep_str helper, add tests 2026-04-08 20:52:51 -10:00
J. Nick Koston c8e636f253 Add unit tests for small_pow10, uint32_to_str, frac_to_str 2026-04-08 20:51:06 -10:00
J. Nick Koston d8e586609f [core] Optimize value_accuracy_to_buf to avoid snprintf
Replace snprintf("%.*f") with integer-based formatting for finite
float values with accuracy_decimals 0-3 (covers virtually all sensor
usage). Falls back to snprintf for higher accuracy or NaN/Inf.

Uses lrint() with double cast for the multiply to match snprintf's
rounding behavior exactly. The fast path avoids snprintf's heavy
float formatting machinery entirely.

Also optimizes value_accuracy_with_uom_to_buf to append the UOM
string directly instead of going through snprintf.

Adds C++ unit tests that verify output matches snprintf for a range
of values including edge cases.

Benchmark: 92,961ns -> 6,484ns (14.3x faster, 2000 iterations).
2026-04-08 20:46:16 -10:00
0c5f055d45 [core] cpp tests: Allow customizing code generation during tests (#14681)
Co-authored-by: J. Nick Koston <nick@home-assistant.io>
Co-authored-by: J. Nick Koston <nick@koston.org>
2026-03-18 00:16:01 +00:00