perf: migrate to orjson for performance
This commit is contained in:
7
.gitignore
vendored
7
.gitignore
vendored
@@ -5,4 +5,9 @@
|
|||||||
/players.redb*
|
/players.redb*
|
||||||
|
|
||||||
/players*.json*
|
/players*.json*
|
||||||
/b50*.json*
|
/b50*.json*
|
||||||
|
|
||||||
|
/.python-version
|
||||||
|
/uv.lock
|
||||||
|
|
||||||
|
/.venv
|
||||||
9
pyproject.toml
Normal file
9
pyproject.toml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
[project]
|
||||||
|
name = "sdgb-utils-rs"
|
||||||
|
version = "0.1.0"
|
||||||
|
description = "Add your description here"
|
||||||
|
readme = "README.md"
|
||||||
|
requires-python = ">=3.12"
|
||||||
|
dependencies = [
|
||||||
|
"orjson>=3.11.1",
|
||||||
|
]
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import json
|
import orjson as json
|
||||||
import hashlib
|
import hashlib
|
||||||
from typing import Callable
|
from typing import Callable
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
@@ -7,7 +7,7 @@ from decimal import Decimal, getcontext
|
|||||||
SALT = b"Lt2N5xgjJOqRsT5qVt7wWYw6SqOPZDI7"
|
SALT = b"Lt2N5xgjJOqRsT5qVt7wWYw6SqOPZDI7"
|
||||||
|
|
||||||
with open("musicDB.json", "r", encoding="utf-8") as f:
|
with open("musicDB.json", "r", encoding="utf-8") as f:
|
||||||
music_db = json.load(f)
|
music_db = json.loads(f.read())
|
||||||
|
|
||||||
music_db = {entry["id"]: entry for entry in music_db}
|
music_db = {entry["id"]: entry for entry in music_db}
|
||||||
|
|
||||||
@@ -169,19 +169,17 @@ def process(
|
|||||||
output_file: str,
|
output_file: str,
|
||||||
):
|
):
|
||||||
record_time()
|
record_time()
|
||||||
with open(input_file, "r", encoding="utf-8") as f:
|
with open(input_file, "rb") as f:
|
||||||
data = json.load(f)
|
data = json.loads(f.read())
|
||||||
print(f"loaded, cost {record_time():.2f}s")
|
print(f"loaded, cost {record_time():.2f}s")
|
||||||
|
|
||||||
record_time()
|
|
||||||
for entry in data:
|
for entry in data:
|
||||||
salted_hash_userid(entry)
|
salted_hash_userid(entry)
|
||||||
clean_fields(entry)
|
clean_fields(entry)
|
||||||
print(f"processed, cost {record_time():.2f}s")
|
print(f"processed, cost {record_time():.2f}s")
|
||||||
|
|
||||||
record_time()
|
with open(output_file, "wb") as f:
|
||||||
with open(output_file, "w", encoding="utf-8") as f:
|
f.write(json.dumps(data))
|
||||||
json.dump(data, f, ensure_ascii=False)
|
|
||||||
print(f"written out, cost {record_time():.2f}s")
|
print(f"written out, cost {record_time():.2f}s")
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|||||||
Reference in New Issue
Block a user