Commit Graph
3210 Commits
Author SHA1 Message Date
J. Nick Koston afb3acedeb Merge remote-tracking branch 'origin/scheduler-process-to-add-fast-path' into integration 2026-03-17 12:07:25 -10:00
J. Nick Koston c88a01227c Merge remote-tracking branch 'upstream/dev' into integration 2026-03-17 10:21:29 -10:00
J. Nick Koston f57c9d0501 Merge branch 'dev' into codspeed-benchmarks 2026-03-17 08:45:33 -10:00
Jonathan Swoboda b083491e74 [microphone] Switch IDF test to new I2S driver (#14886) 2026-03-17 13:46:32 -04:00
J. Nick Koston 4003406f8b Remove Scheduler_NextScheduleIn benchmark — too cheap, flaps 2026-03-17 02:06:16 -10:00
J. Nick Koston e14443b9c3 Fix ProtoSize_Varint benchmarks: prevent constant folding
The compiler constant-folds ProtoSize::varint(42) to 1 and optimizes
the entire inner loop to a single addition, causing ~62ns jitter-dominated
measurements. Use varying inputs (i & 0x7F for small, 0xFFFF0000 | i for
large) so each call computes a real result.
2026-03-17 01:50:36 -10:00
J. Nick Koston b87b4102e0 Fix binary path extraction and defer benchmark compile error
- Use BENCHMARK_BINARY= marker for reliable binary path extraction
  instead of fragile tail -1 (PlatformIO can print warnings after path)
- Fix Scheduler_Defer: defer() is protected on Component, use
  set_timeout(delay=0) directly on Scheduler instead
2026-03-17 01:42:37 -10:00
J. Nick Koston d5f2c93e68 Add benchmarks for set_timeout, set_interval, and defer registration
Measures the cost of registering scheduler items:
- Scheduler_SetTimeout: set_timeout with 1s delay (heap path)
- Scheduler_SetInterval: set_interval with 1s period (heap path + offset calc)
- Scheduler_Defer: Component::defer (set_timeout with delay=0)

Uses i%5 for IDs to exercise the cancel-existing-timer path that
happens when re-registering with the same ID.
2026-03-17 01:38:19 -10:00
J. Nick Koston 804e2330ec Ifdef out WarnIfComponentBlockingGuard for benchmark builds
Add USE_BENCHMARK define to benchmark build flags. Guard the
warn_blocking call in finish() with #ifndef USE_BENCHMARK so
scheduler benchmarks using fake monotonic time don't trigger
the underflow (fake now > real millis()).

Remove BenchComponent — no longer needed with the ifdef.
2026-03-17 01:16:34 -10:00
J. Nick Koston e01670eed8 Revert core changes, use intervals with fake time for scheduler benchmark
The warn_blocking underflow only happens with fake time in benchmarks,
not in production (millis() is monotonic). Accept the consistent
overhead from one warning per call — CodSpeed regression detection
works on relative changes, not absolute values.
2026-03-17 01:14:39 -10:00
J. Nick Koston 885d7c3938 [core] Fix uint32_t underflow in WarnIfComponentBlockingGuard::finish()
When curr_time (from millis()) is less than started_ (the `now` passed
to scheduler.call()), the subtraction wraps to a huge value (~4 billion).
This triggers spurious blocking warnings with nonsensical times.

This can happen when the scheduler's execute_item_() returns a millis()
value that subsequent items use as their guard start, but the next
scheduler.call() passes a `now` value from a slightly different source.

Fix by skipping the blocking check when curr_time < started_ (underflow).

Also restore the scheduler firing benchmark to use intervals with
monotonically increasing fake time, now that the guard handles underflow.
2026-03-17 01:10:57 -10:00
J. Nick Koston 1f9380ddc0 Fix scheduler firing benchmark: no inner loop, warm-up call
- Revert component.h change (no core changes for benchmarks)
- Remove -DWARN_IF_BLOCKING_OVER_MS from build flags (can't shadow constexpr)
- Drop inner loop — 5 heap pops + callbacks + pushes per call is well
  above CodSpeed's 60ns instrumentation overhead
- Add warm-up call before benchmark loop to trigger the blocking guard
  once and ramp the threshold
- interval=0 causes infinite loop, must use interval=1 with fake time
2026-03-17 01:05:04 -10:00
J. Nick Koston ec60e2c228 Fix scheduler benchmark: use fake time with guard disabled at compile time
interval=0 causes infinite loop (reschedules at same time, never breaks).
interval=1 with millis() doesn't work (real time doesn't advance fast
enough between inner iterations for intervals to re-fire).

Solution: use interval=1 with monotonically increasing fake time (now++)
and disable WarnIfComponentBlockingGuard at compile time via
-DWARN_IF_BLOCKING_OVER_MS=UINT32_MAX in benchmark build flags. This
prevents the guard's (millis() - started_) underflow when fake time
exceeds real millis().
2026-03-17 01:00:06 -10:00
J. Nick Koston d7be19703b Fix scheduler intervals not firing and warn_blocking
Use interval=0 so all 5 intervals fire unconditionally every call().
Pass real millis() to scheduler.call() so WarnIfComponentBlockingGuard
doesn't see fake time ahead of wall clock (which causes uint32_t
underflow in the blocking time calculation).
2026-03-17 00:54:29 -10:00
J. Nick Koston 4565167bec Fix scheduler benchmark triggering warn_blocking
WarnIfComponentBlockingGuard compares the `now` passed to
scheduler.call() against real millis() in finish(). Using fake time
ahead of real millis() caused uint32_t underflow in the guard, triggering
blocking warnings. Fix by reading real millis() at the start of each
outer iteration so fake time stays close to wall clock.
2026-03-17 00:53:10 -10:00
J. Nick Koston 662780bcc6 Simplify scheduler now comment 2026-03-17 00:38:48 -10:00
J. Nick Koston e45cfc5451 Revert scheduler now reset — must be monotonic for millis_64_from_
millis_64_from_() tracks 32-bit rollovers, so going backwards in time
would appear as a ~49 day forward jump. Keep now monotonically
increasing across all iterations. With 2000 inner iterations per outer
iteration, overflow is not a practical concern.
2026-03-17 00:37:58 -10:00
J. Nick Koston ca2cf4044c Fix stray quote in main.cpp and scheduler time overflow
- Remove trailing " from AUTO GENERATED INCLUDE BLOCK END comment
- Reset scheduler `now` at start of each outer iteration to avoid
  unbounded growth toward UINT32_MAX across benchmark iterations
2026-03-17 00:35:53 -10:00
J. Nick Koston eb94465174 Add logger benchmarks for format string hot paths
Three benchmarks covering the most common ESP_LOGW patterns:
- Logger_NoFormat: plain string, no format specifiers (fastest path)
- Logger_3Uint32: 3x uint32_t (common for status/diagnostics)
- Logger_3Float: 3x float with precision (common for sensor values)
2026-03-17 00:23:15 -10:00
J. Nick Koston 8c058cd725 Replace hand-encoded protobuf bytes with programmatic encoding in decode benchmarks
Encode messages once in setup using the real protobuf API, then decode
the resulting bytes in the benchmark loop. This keeps decode benchmarks
automatically in sync with the protobuf schema — hand-encoded byte
arrays would silently break when fields change.
2026-03-17 00:20:52 -10:00
J. Nick Koston 3fdb201f59 Suppress blocking warnings in scheduler benchmarks
Under valgrind, 2000 inner iterations take long enough in wall clock
to trigger WarnIfComponentBlockingGuard. Use a BenchComponent subclass
that sets warn_if_blocking_over_ to UINT16_MAX to prevent log noise.
2026-03-17 00:16:44 -10:00
J. Nick Koston ed539e17ff Add scheduler benchmark with 5 intervals firing per call
Adds Scheduler_Call_5IntervalsFiring: 5 intervals with 1ms period,
time advancing each inner iteration so all 5 fire every call().
This benchmarks the real scheduler hot path where callbacks execute.
2026-03-16 23:57:39 -10:00
J. Nick Koston 2061fa2393 Add inner loops to _Fresh benchmarks for CodSpeed consistency
Both _Fresh variants now use kInnerIterations with fresh buffer
creation inside the inner loop. This amortizes CodSpeed's per-iteration
instrumentation overhead while still measuring alloc+calc+encode per item.
2026-03-16 23:53:19 -10:00
J. Nick Koston 5d5a48c369 Fix _Fresh benchmark consistency and address review nits
- Remove inner loop from CalcAndEncode_DeviceInfoResponse_Fresh to match
  SensorStateResponse_Fresh — both now measure single alloc+encode per
  iteration as intended for heap allocation cost benchmarking
- Add comments documenting why _Fresh variants skip inner loops
- Add first-wins comment to load_component_yaml_configs
- Clean up .gitignore template comment
2026-03-16 23:52:27 -10:00
J. Nick Koston 8e4091baa3 Increase inner iterations from 1000 to 2000 to reduce jitter 2026-03-16 23:40:18 -10:00
J. Nick Koston dd52c91290 Add inner iteration loops to amortize CodSpeed instrumentation overhead
Sub-microsecond benchmarks are dominated by the ~60ns per-iteration
valgrind start/stop cost in CodSpeed simulation mode. Add kInnerIterations
(1000) inner loops to all fast benchmarks so the actual work dominates.
Move DoNotOptimize calls outside inner loops to prevent artificial overhead.

Also address review feedback:
- Use tokenless CodSpeed (public repo, no CODSPEED_TOKEN needed)
- Fix warning message to show component-specific path
- Fix stray ". :" in error message
- Verify pinned SHA on re-runs to prevent stale checkouts
2026-03-16 23:32:49 -10:00
J. Nick Koston 5b073ca520 Fix stale comment in main.cpp, simplify CI binary extraction 2026-03-16 22:48:39 -10:00
J. Nick Koston e34855b92e Add _Fresh variants to measure heap allocation cost in encode benchmarks 2026-03-16 22:44:16 -10:00
J. Nick Koston 621ba4d5b4 Set loop_interval to 0 in ApplicationLoop benchmark to skip sleep 2026-03-16 22:34:41 -10:00
J. Nick Koston 68cec9cc28 Add real Application::loop() benchmark, call original_setup() in main
- Call original_setup() in benchmark main.cpp so code-generated App
  initialization (pre_setup, area/device registration, looping_components_
  init) runs before benchmarks
- Restore ApplicationLoop_Empty benchmark that calls the actual App.loop()
2026-03-16 22:32:36 -10:00
J. Nick Koston a92147e1c9 Remove BM_ prefix, drop application loop benchmark, fix core includes
- Remove BM_ prefix from all benchmark names (unnecessary convention)
- Remove bench_application_loop.cpp (App needs pre_setup/setup which
  requires full code generation; will revisit as integration benchmark)
- Fix extra_include_dirs to use os.path.relpath for sibling directories
2026-03-16 22:27:03 -10:00
J. Nick Koston 456a7d740e Remove application loop benchmark - doesn't test real loop path 2026-03-16 22:14:51 -10:00
J. Nick Koston 7c95a83c6c Remove stale codspeed_plan.md reference from main.cpp 2026-03-16 21:31:31 -10:00
J. Nick Koston a6219434b9 Move core benchmarks to tests/benchmarks/core/
Core is not a component — its benchmarks belong in tests/benchmarks/core/
not tests/benchmarks/components/core/. Add extra_include_dirs parameter
to build_and_run to support non-component benchmark directories.
2026-03-16 20:52:53 -10:00
J. Nick Koston 9c148da76a Add core benchmarks dir, fix core pseudo-component, use simulation mode
- Move scheduler/loop/helpers benchmarks to tests/benchmarks/components/core/
- Add random_float and random_uint32 benchmarks (from ol.yaml)
- Fix core pseudo-component crash: skip components where get_component()
  returns None when adding dependencies to config
- Use CodSpeed simulation mode (CPU instruction counting) for reproducible
  CI results instead of walltime
2026-03-16 20:49:48 -10:00
J. Nick Koston 38ff332fec [core] Add CodSpeed C++ benchmarks for protobuf and main loop
Add automated benchmarks using Google Benchmark to prevent performance
regressions in the API protobuf encoding/decoding and core loop paths.

Benchmarks cover:
- Protobuf encode: SensorState, BinarySensorState, HelloResponse,
  LightState, DeviceInfoResponse (20 nested devices + 20 areas)
- Protobuf decode: HelloRequest, SwitchCommand, LightCommand
- Protobuf calculate_size and full calc+encode send path
- Varint parse/encode/size for various value ranges
- Scheduler call/next_schedule_in with idle and active timers
- Application loop component dispatch and blocking guard overhead

Infrastructure:
- Extract shared build logic from cpp_unit_test.py into test_helpers.py
- Add cpp_benchmark.py mirroring the unit test build pattern
- Support benchmark.yaml per component dir for declaring dependencies
- Add CodSpeed CI workflow triggered on api/core changes
- Fix ProtoMessage protected destructor on host platform
2026-03-16 19:25:46 -10:00
J. Nick Koston eb34cf0142 Merge remote-tracking branch 'upstream/esp32-sram1-as-iram' into integration 2026-03-16 15:26:12 -10:00
J. Nick Koston bd3287a554 [esp32] Add sram1_as_iram option for +40KB IRAM on original ESP32
Add a new `sram1_as_iram` option under `esp32 > framework > advanced`
that enables CONFIG_ESP_SYSTEM_ESP32_SRAM1_REGION_AS_IRAM, reclaiming
40KB of SRAM1 memory as additional IRAM on the original ESP32.

This requires a bootloader from ESP-IDF v5.1 or later. USB flashing
updates the bootloader automatically, but OTA does not. At boot,
ESPHome now detects the bootloader version and suggests enabling
this option when the bootloader is compatible.
2026-03-16 15:24:12 -10:00
J. Nick Koston b142557979 [ethernet] Add RP2040 W5500 Ethernet support (#14820) 2026-03-16 18:26:06 +00:00
J. Nick Koston 77bbd70810 Merge remote-tracking branch 'origin/inline-ansi-reset' into integration 2026-03-15 20:42:27 -10:00
J. Nick KostonCopilot Autofix powered by AIpre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
9948adc6a0 [runtime_image] Add esp-dsp dependency for JPEGDEC SIMD on ESP32 (#14840)
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
2026-03-15 18:15:01 -10:00
J. Nick Koston ccb467b219 [fastled] Include esp_lcd IDF component for ESP32-S3 compatibility (#14839) 2026-03-15 18:14:41 -10:00
J. Nick Koston 870f93d797 Merge remote-tracking branch 'upstream/dev' into integration 2026-03-15 14:30:46 -10:00
Bonne EgglestonandJ. Nick Koston 92d5e7b18c [tests] Fix integration helper to match entities exactly (#14837)
Co-authored-by: J. Nick Koston <nick@home-assistant.io>
2026-03-15 13:02:23 -10:00
J. Nick Koston fdfbcd03af Merge remote-tracking branch 'origin/ethernet-rp2040-w5500-impl' into integration 2026-03-14 15:18:59 -10:00
J. Nick Koston 8ab3e8fa89 [ethernet] Add RP2040 W5500 Ethernet support
Add W5500 SPI Ethernet support for RP2040 boards using arduino-pico's
Wiznet5500lwIP class. Tested on WIZnet W5500-EVB-Pico hardware.

- Add ethernet_component_rp2040.cpp with W5500 implementation
- Add RP2040 members and setters to ethernet_component.h
- Enable RP2040 platform in SPI_SCHEMA and FILTER_SOURCE_FILES
- Add RP2040 validation, code generation, and lwIP_w5500 library
- Add W5500 RP2040 test YAML
2026-03-14 14:38:48 -10:00
J. Nick Koston 610068e538 Merge remote-tracking branch 'upstream/dev' into integration 2026-03-14 12:33:57 -10:00
Jonathan SwobodaandClaude Opus 4.6 417858f098 [psram] Add ESP32-C61 PSRAM support (#14795)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 15:01:49 -04:00
J. Nick Koston 415084d032 Merge remote-tracking branch 'upstream/dev' into integration 2026-03-13 13:42:55 -10:00
J. Nick Koston 56f7b3e61b [ci] Only run integration tests for changed components (#14776) 2026-03-13 13:20:35 -10:00