-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: Use ORJSONResponse for faster JSON serialization in feature server #5930
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
franciscojavierarceo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to get tests passing but approving to unblock
@franciscojavierarceo Test failures are due to transient dependency sqlglot, related to ibis-project/ibis#11882. I have handled it already in #5928 , will rebase this PR once it's merged. |
Signed-off-by: ntkathole <nikhilkathole2683@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| float_precision=18, | ||
| ) | ||
| return response_dict | ||
| return ORJSONResponse(content=response_dict) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 ORJSONResponse serializes NaN/Infinity as null, changing API behavior
Switching from JSONResponse to ORJSONResponse changes how NaN and Infinity float values are serialized in the API response.
Click to expand
Behavior Change
The standard json module (used by JSONResponse) serializes special float values as:
float('nan')→NaNfloat('inf')→Infinityfloat('-inf')→-Infinity
While orjson (used by ORJSONResponse) serializes them as:
float('nan')→nullfloat('inf')→nullfloat('-inf')→null
Impact
The Feast codebase explicitly uses NaN values for missing data. In sdk/python/feast/proto_json.py:99-101:
# Convert each null as NaN.
message.double_list_val.val.extend(
[item if item is not None else float("nan") for item in value]
)And tests in sdk/python/tests/unit/test_proto_json.py:65 verify NaN is preserved:
assertpy.assert_that(feature_vector_json["values"][5][3]).is_nan()With ORJSONResponse, clients that previously received NaN in responses will now receive null, which has different semantics (missing value vs. not-a-number). This is a breaking change for API consumers that rely on distinguishing between null and NaN values.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@franciscojavierarceo Thoughts on this ?
What this PR does / why we need it:
This PR improves the latency of the online feature server by using FastAPI's built-in ORJSONResponse instead of the default JSONResponse. This leverages orjson, a fast JSON library written in Rust, for response serialization.
Changes
When returning a dict from a FastAPI endpoint, FastAPI uses Python's standard json module for serialization. By using ORJSONResponse, we leverage orjson which is written in Rust and provides significantly faster JSON encoding.