My Home Assistant finally stopped lagging when I replaced SQLite with PostgreSQL.