claws / aioprometheus

A Prometheus Python client library for asyncio-based applications
176 stars 21 forks source link

Use orjson #77

Closed binary0111 closed 2 years ago

binary0111 commented 2 years ago

A simple benchmark (there are plenty of others available on the internet):

In [1]: import json, orjson

In [2]: test_dict = {'bfdfsd': 223, 'afdsfds': '1freresr', '1':4, '3': '434w3', 'gfdgd': 'trttdrfg' }

In [3]: timeit json.loads(json.dumps(test_dict, sort_keys=True))
4.98 µs ± 78.9 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)

In [4]: timeit orjson.loads(orjson.dumps(test_dict, option=(orjson.OPT_SORT_KEYS|orjson.OPT_NON_STR_KEYS)))
778 ns ± 2.09 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)

In [5]: timeit orjson.loads(orjson.dumps(test_dict, option=orjson.OPT_SORT_KEYS))
692 ns ± 13.9 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
claws commented 2 years ago

Are you able to rebase your pull request?

binary0111 commented 2 years ago

Are you able to rebase your pull request?

Done!

codecov-commenter commented 2 years ago

Codecov Report

Merging #77 (c293a94) into master (bd0f62c) will decrease coverage by 0.02%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master      #77      +/-   ##
==========================================
- Coverage   95.54%   95.51%   -0.03%     
==========================================
  Files          17       17              
  Lines         785      780       -5     
  Branches      115      114       -1     
==========================================
- Hits          750      745       -5     
  Misses         19       19              
  Partials       16       16              
Impacted Files Coverage Δ
src/aioprometheus/collectors.py 97.77% <100.00%> (-0.07%) :arrow_down:
src/aioprometheus/metricdict.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update bd0f62c...c293a94. Read the comment docs.

claws commented 2 years ago

Probably ok as is. I'm planning on adding a scheduled ci job to the project to catch API evolution in unpinned deps.

On Sat, 21 May 2022, 22:15 binary0111, @.***> wrote:

@.**** commented on this pull request.

In requirements.txt https://github.com/claws/aioprometheus/pull/77#discussion_r878691520:

@@ -1 +1,2 @@ +orjson

Might not be the best idea to pin orjson to a specific version as its widely used including by developers building webapps with fastapi / starlette. Pinning the version here might cause dependency conflicts with those apps when future version are released or if someone is still on an older version for some reason. Orjson's api has been stable for a long time and is unlikely to change unless the json standard library changes. Maybe we could do something like orjson>=3.6.0,<4.0.0?

— Reply to this email directly, view it on GitHub https://github.com/claws/aioprometheus/pull/77#discussion_r878691520, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJ44UM23VMLFGYPBTNBZMDVLDLGTANCNFSM5VJ5IEHQ . You are receiving this because you commented.Message ID: @.***>

claws commented 2 years ago

Thanks.

claws commented 2 years ago

This change is included in version 22.5.0 which is up on PyPI. Thanks.