Speeding up HA

Hi all,

I’ve been looking at ways to speed up Home Assistant. I decided to start this thread as a place to discuss ways to do this.

I’ve come up with a few ideas:

  1. slot dataclasses (I’ve already started to do this)
  2. use uvloop instead of the standard asyncio loop
  3. replace orjson with msgspec
  4. pypy/Cython (yeah, this might be ugly)

I’ve run some profiles with various states which I can share.

  1. steady state
  2. randomly clicking around the UI
  3. running lots of services via automation and some templates

Anyone else have any ideas/feedback?

I for one would love to see a guide/ideas on properly treating history/stats based on what you want to know versus what HA thinks you want to know. I am just now digging into how best to set up things and I believe the majority of users just don’t know or don’t think it through.

Examples – I have a Sports Standings and Scores set of REST and template entities. History on this (to me) is meaningless. IMHO that applies to 90% of entities. I could care less about stats for these except possibly what was the state before that restart. But last week at 2:00am? I could care less.

Or my BBQ sensors for a TUYA based thermometer … or my media players … etc/etc.

It seems as though the standard in HA is record everything unless you tell me not to. Which to me personally is counter-intuitive unless I am wrong. I would think it should be record only the last state unless you want history like for Energy use or something. And the user should be assigned to select what those things are, not HA.

Just my thoughts … as I am only starting to think through this I might be way off.

I just took a peak at me DB and I see this:

image

Looks awful large to me for a lot of nothing. Has to impact the performance.

From the documentation on history I think it is not logically done from the start. It is “ON” for everything unless you tell me to not record. I think it should be the opposite UNLESS that impacts things like a reboot and a switch state is not known then. But I do not know and would appreciate someone telling me differently.

As in … “Is there a way to only record the last state without keeping a history of those states ?”


Filters are applied as follows:

  1. No filter
  • All entities included
  1. Only includes
  • Entity listed in entities include: include
  • Otherwise, entity matches domain include: include
  • Otherwise, entity matches glob include: include
  • Otherwise: exclude
  1. Only excludes
  • Entity listed in exclude: exclude
  • Otherwise, entity matches domain exclude: exclude
  • Otherwise, entity matches glob exclude: exclude
  • Otherwise: include
  1. Domain and/or glob includes (may also have excludes)
  • Entity listed in entities include: include
  • Otherwise, entity listed in entities exclude: exclude
  • Otherwise, entity matches glob include: include
  • Otherwise, entity matches glob exclude: exclude
  • Otherwise, entity matches domain include: include
  • Otherwise: exclude
  1. Domain and/or glob excludes (no domain and/or glob includes)
  • Entity listed in entities include: include
  • Otherwise, entity listed in exclude: exclude
  • Otherwise, entity matches glob exclude: exclude
  • Otherwise, entity matches domain exclude: exclude
  • Otherwise: include
  1. No Domain and/or glob includes or excludes
  • Entity listed in entities include: include
  • Otherwise: exclude

That’s pretty huge. And it has got to effect startup performance when the database schemas change.

I hadn’t thought about the database, but maybe there should be some sort of conditional purge along with your suggestion?