Extended the functionality, and increased the performance of the builtin json library for Pyjinn - #79
Open
SmartBoty wants to merge 2 commits into
Open
Extended the functionality, and increased the performance of the builtin json library for Pyjinn#79SmartBoty wants to merge 2 commits into
SmartBoty wants to merge 2 commits into
Conversation
…tin json library for Pyjinn
Upgraded `json.py` to use `Gson` instead of `JsonParser`: Significant performance improvements for deserialization and exposing `dumps`
Built in `json.py`:
1 280 307.60 ns / call (~1.28 ms)
This `json.py`:
852 362.57 ns / call (~0.85 ms)
Notes:
- I tried to match the header to the builtin json.py-s header, but may still require adjustments
## Code used to determine these values:
```py
System = JavaClass("java.lang.System")
data = (
r"""
{
"version": "1.2.0",
"generated": "2026-07-21T14:30:00Z",
"success": true,
"metadata": {
"creator": "Test Generator",
"description": "JSON parser stress test",
"tags": [
"json",
"parser",
"test",
"nested",
"unicode"
],
"unicode": "こんにちは 🌍 Привет مرحبا",
"escaped": "Line1\nLine2\tTabbed\\Backslash\"Quote\""
},
"numbers": {
"zero": 0,
"negative": -42,
"integer": 123456789,
"float": 3.1415926535,
"negativeFloat": -0.000123,
"scientific1": 6.022e23,
"scientific2": -1.6e-19,
"large": 999999999999999,
"small": 0.000000000001
},
"emptyObject": {},
"emptyArray": [],
"nullValue": null,
"users": [
{
"id": 1,
"name": "Alice",
"active": true,
"roles": [
"admin",
"developer"
],
"address": {
"street": "123 Main St",
"city": "Exampleville",
"zip": "12345",
"coords": {
"lat": 41.40338,
"lon": 2.17403
}
},
"scores": [
95,
88,
76,
100
]
},
{
"id": 2,
"name": "Bob",
"active": false,
"roles": [
"user"
],
"address": {
"street": "456 Side Rd",
"city": "Somewhere",
"zip": null,
"coords": {
"lat": -33.865143,
"lon": 151.2099
}
},
"scores": []
},
{
"id": 3,
"name": "Charlie",
"active": true,
"roles": [],
"address": {},
"scores": [
50,
75.5,
-12,
1.2e4
]
}
],
"matrix": [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
],
"mixedArray": [
null,
true,
false,
123,
-45.67,
"hello",
{
"nested": [
{
"a": 1
},
{
"b": 2
}
]
},
[],
{}
],
"config": {
"graphics": {
"width": 1920,
"height": 1080,
"fullscreen": false,
"vsync": true
},
"audio": {
"master": 0.8,
"music": 0.5,
"effects": 0.9
},
"network": {
"host": "localhost",
"port": 8080,
"timeout": 15.5
}
},
"deep": {
"level1": {
"level2": {
"level3": {
"level4": {
"level5": {
"message": "Reached the bottom!"
}
}
}
}
}
},
"inventory": [
{
"id": "itm001",
"name": "Sword",
"stats": {
"damage": 25,
"durability": 98
},
"enchantments": [
"Fire",
"Sharpness"
]
},
{
"id": "itm002",
"name": "Shield",
"stats": {
"defense": 40,
"durability": 100
},
"enchantments": []
},
{
"id": "itm003",
"name": "Potion",
"stats": null,
"stack": 15
}
],
"objectArray": [
{
"k": "a",
"v": 1
},
{
"k": "b",
"v": 2
},
{
"k": "c",
"v": {
"nested": true
}
}
]
}
""")
start = System.nanoTime()
for _ in range(10000):
loads(data)
print(f"Average: {(System.nanoTime()-start)/10000}")
```
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Upgraded
json.pyto useGsoninstead ofJsonParser: Significant performance improvements for deserialization and exposingdumpsBuilt in
json.py:1 280 307.60 ns / call (~1.28 ms)
This
json.py:852 362.57 ns / call (~0.85 ms)
Notes:
Code used to determine these values: