1
mirror of https://github.com/home-assistant/core synced 2024-08-06 09:34:49 +02:00
ha-core/homeassistant/util
J. Nick Koston 8b067e83f7
Initial orjson support take 3 (#73849)
* Initial orjson support take 2

Still need to work out problem building wheels

--

Redux of #72754 / #32153 Now possible since the following is solved:
ijl/orjson#220 (comment)

This implements orjson where we use our default encoder.  This does not implement orjson where `ExtendedJSONEncoder` is used as these areas tend to be called far less frequently.  If its desired, this could be done in a followup, but it seemed like a case of diminishing returns (except maybe for large diagnostics files, or traces, but those are not expected to be downloaded frequently).

Areas where this makes a perceptible difference:
- Anything that subscribes to entities (Initial subscribe_entities payload)
- Initial download of registries on first connection / restore
- History queries
- Saving states to the database
- Large logbook queries
- Anything that subscribes to events (appdaemon)

Cavets:
orjson supports serializing dataclasses natively (and much faster) which
eliminates the need to implement `as_dict` in many places
when the data is already in a dataclass. This works
well as long as all the data in the dataclass can also
be serialized. I audited all places where we have an `as_dict`
for a dataclass and found only backups needs to be adjusted (support for `Path` needed to be added for backups).  I was a little bit worried about `SensorExtraStoredData` with `Decimal` but it all seems to work out from since it converts it before it gets to the json encoding cc @dgomes

If it turns out to be a problem we can disable this
with option |= [orjson.OPT_PASSTHROUGH_DATACLASS](https://github.com/ijl/orjson#opt_passthrough_dataclass) and it
will fallback to `as_dict`

Its quite impressive for history queries
<img width="1271" alt="Screen_Shot_2022-05-30_at_23_46_30" src="https://user-images.githubusercontent.com/663432/171145699-661ad9db-d91d-4b2d-9c1a-9d7866c03a73.png">

* use for views as well

* handle UnicodeEncodeError

* tweak

* DRY

* DRY

* not needed

* fix tests

* Update tests/components/http/test_view.py

* Update tests/components/http/test_view.py

* black

* templates
2022-06-22 21:59:51 +02:00
..
yaml Improve YAML Dump times with C Dumper (#73424) 2022-06-13 13:14:30 -07:00
__init__.py Make TypeVars private (1) (#68205) 2022-03-17 18:52:38 +01:00
aiohttp.py Revert fix MultiDict typing with multidict-6.0.0 (#64733) (#64792) 2022-01-23 23:22:16 +01:00
async_.py Make database access in the eventloop raise an exception (#71547) 2022-05-09 15:22:08 -05:00
color.py Update mypy to 0.960 (#72481) 2022-05-25 11:42:14 -07:00
decorator.py Improve typing [util.decorator] (#67087) 2022-02-23 20:58:42 +01:00
distance.py Import Callable from collections.abc (1) (#56775) 2021-09-29 16:32:11 +02:00
dt.py Add template as_timedelta (#71801) 2022-05-23 19:32:22 +02:00
executor.py Remove ThreadPoolExecutor shutdown backport (#66735) 2022-02-17 10:39:33 -06:00
file.py Use atomicwrites for mission critical core files (#59606) 2021-11-15 11:19:31 +01:00
json.py Initial orjson support take 3 (#73849) 2022-06-22 21:59:51 +02:00
location.py Improve typing [util.location] (#70893) 2022-04-27 17:20:56 +02:00
logging.py Improve typing [util.logging] (#70894) 2022-04-27 22:26:56 +02:00
network.py Improve error handling process_play_media_url (#68322) 2022-03-20 20:25:15 -07:00
package.py Add type ignore error codes [util] (#66777) 2022-02-18 11:30:59 +01:00
percentage.py Make TypeVars private (1) (#68205) 2022-03-17 18:52:38 +01:00
pil.py Update typing 03 (#48015) 2021-03-17 21:46:07 +01:00
pressure.py Add support for converting to and from mmHg (#64844) 2022-01-24 22:57:56 +01:00
process.py Move disallow-any-generics to mypy.ini (#63917) 2022-01-11 13:33:25 -08:00
read_only_dict.py Make TypeVars private (1) (#68205) 2022-03-17 18:52:38 +01:00
speed.py Add speed conversion function & add speed to units system (#53846) 2021-11-09 08:12:28 +01:00
ssl.py Lint suppression cleanups (#47248) 2021-03-02 09:02:04 +01:00
temperature.py Allow customizing unit for temperature and pressure sensors (#64366) 2022-03-30 15:43:04 +02:00
thread.py Ensure shutdown does not deadlock (#49282) 2021-04-18 08:55:51 -10:00
timeout.py Rewrite of not a == b occurances (#48132) 2021-03-20 01:27:04 +01:00
ulid.py Sync event timed_fired and the context ulid time (#71854) 2022-05-14 12:12:08 -07:00
unit_system.py Add type ignore error codes [util] (#66777) 2022-02-18 11:30:59 +01:00
uuid.py Improve performance of generating non-cryptographically secure uuids (#41314) 2020-10-07 16:37:01 +02:00
volume.py Add device class gas and enable statistics for it (#54110) 2021-08-11 09:58:19 -07:00