Skip to content

ENH: Add C++ from_dict and from_json methods for csp.Struct - #758

Open
aadya940 wants to merge 3 commits into
Point72:mainfrom
aadya940:from_methods_cpp
Open

ENH: Add C++ from_dict and from_json methods for csp.Struct#758
aadya940 wants to merge 3 commits into
Point72:mainfrom
aadya940:from_methods_cpp

Conversation

@aadya940

@aadya940 aadya940 commented Sep 6, 2026

Copy link
Copy Markdown

Fixes #518

This change replaces from_dict's pure Python implementation with a C++ one, and adds a new from_json method to build a csp.Struct directly from a JSON string. from_json parses with rapidjson and writes into the struct fields, with a template specialization per type. from_dict is much simpler since fromPython already exists.

The speedup is between 11-12x for both of them!

NOTES:
Not every struct can take the C++ path. StructMeta only keeps normalized field types, so annotations like Literal[1,2,3] or Dict[str, SomeEnum] are removed before C++ can see them and the values cannot be reconstructed. Those structs keep using the Python implementation, this is pre-decided per class. from_json is stricter than from_dict here since JSON can't carry Python objects at all.

…cases which may not be supported

Signed-off-by: Aadya Chinubhai <aadyachinubhai@gmail.com>
Signed-off-by: Aadya Chinubhai <aadyachinubhai@gmail.com>
Signed-off-by: Aadya Chinubhai <aadyachinubhai@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

C++ implementation for csp.Struct from_dict/from_json

1 participant