Overview
msgspec 0.7, released on June 20, 2022, accelerates JSON string decoding and optimizes memory allocations.
Main Features
Accelerated JSON decoding
JSON string decoding is optimized with a new SIMD parser, offering 2-5x gains over the previous version.
python
import msgspec
# Fast decoding of large JSON responses
class Item(msgspec.Struct):
id: int
name: str
price: float
data = b'[{"id":1,"name":"A","price":9.99}]'
items = msgspec.json.decode(data, type=list[Item])
print(items[0].price) # 9.99
Memory optimization
Memory allocations are reduced during decoding, lowering garbage collector pressure.
python
import msgspec
# Reusable decoder to reduce allocations
dec = msgspec.json.Decoder(type=dict)
for line in open('data.jsonl', 'rb'):
obj = dec.decode(line)
# processing...
