Skip to content

improve python performance - #73

Open
jacopocinaark wants to merge 4 commits into
masterfrom
feature/22400-ImprovePythonPerformance
Open

jacopocinaark wants to merge 4 commits into
masterfrom
feature/22400-ImprovePythonPerformance

Conversation

@jacopocinaark

Copy link
Copy Markdown
Contributor

improve python performance

ref: #22400

Copilot AI lite review requested due to automatic review settings September 16, 2026 09:44
@jacopocinaark
jacopocinaark requested a review from a team as a code owner September 16, 2026 09:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Preserve jsons key encoding to avoid breaking non-primitive and enum key deserialization.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Improves Python performance by optimizing Artesian JSON dictionary serialization.

Changes:

  • Adds fast paths for primitive and datetime values.
  • Simplifies dictionary iteration and deserialization handling.
File summaries
File Summary
src/Artesian/_ClientsExecutor/ArtesianJsonSerializer.py Critical (3 votes): str(k) changes established jsons encoding for non-primitive keys, breaking enum round trips. Retain the jsons.dump fallback for this branch.
Review details

Suppressed comments (1)

src/Artesian/_ClientsExecutor/ArtesianJsonSerializer.py:70

  • This fast path also catches subclasses of the scalar types. An IntEnum is an int, so returning it here bypasses the configured use_enum_name=True serializer and emits its numeric value instead of its enum name. Restrict the shortcut to exact scalar types (or explicitly exclude Enum) so subclasses still go through jsons.
        elif isinstance(v, (str, int, float, bool)) or v is None:
            v_out = v
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

elif isinstance(k, (str, int, float, bool)) or k is None:
k_out = k
else:
k_out = str(k)
Copilot AI review requested due to automatic review settings September 16, 2026 09:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Restore jsons.dump for non-primitive keys to preserve configured serializers.

Review details

Suppressed comments (1)

src/Artesian/_ClientsExecutor/ArtesianJsonSerializer.py:64

  • This replaces the existing jsons.dump(key, key_transformer=None, **kwargs) fallback with str(k), so non-primitive keys no longer use the configured serializers. For example, an Enum key is emitted as Purpose.BID instead of the enum-name behavior configured by use_enum_name=True, and custom key serializers are skipped. Keep the jsons.dump fallback for this branch; only the primitive/datetime fast paths should bypass it.
            k_out = str(k)
  • Files reviewed: 1/1 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Copilot AI review requested due to automatic review settings September 16, 2026 10:02
@jacopocinaark
jacopocinaark requested a review from a team as a code owner September 16, 2026 10:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Fast paths bypass configured jsons serialization for enum and non-primitive mapping keys.

Review details

Suppressed comments (2)

src/Artesian/_ClientsExecutor/ArtesianJsonSerializer.py:63

  • Non-primitive mapping keys used to go through jsons.dump, but str(k) bypasses registered serializers and the active options. For example, an Enum key now becomes "MyEnum.Member" instead of the configured enum name ("Member"), changing the emitted Key and potentially breaking the API payload. Keep the jsons fallback for this branch.
        else:

src/Artesian/_ClientsExecutor/ArtesianJsonSerializer.py:68

  • This primitive fast path also matches IntEnum members. Returning one directly bypasses jsons' use_enum_name=True, so when the result is passed to requests' JSON encoder it is emitted as its numeric value instead of its enum name. Check enum types before this branch or keep enum values on the jsons serialization path.
            v_out = dt_ser(v, **kwargs)
  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Copilot AI review requested due to automatic review settings September 16, 2026 10:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Moderate serializer issues remain unresolved.

Review details

Suppressed comments (2)

src/Artesian/_ClientsExecutor/ArtesianJsonSerializer.py:64

  • This changes the non-primitive-key behavior from jsons.dump(key, key_transformer=None, **kwargs) to str(k). That bypasses registered serializers and breaks the mapping serializer/deserializer contract for supported key types such as custom objects or dates, because their serialized structure is replaced by a Python repr/string and cannot be loaded back into the declared key type. Keep the primitive/datetime fast paths, but retain the jsons.dump fallback for other keys.
            k_out = str(k)

src/Artesian/_ClientsExecutor/ArtesianJsonSerializer.py:69

  • The primitive fast path also matches IntEnum and str-based Enum subclasses, returning the enum object instead of letting jsons.dump honor the configured use_enum_name=True. This makes artesianJsonSerialize return an underlying integer/string (or a non-normalized enum) for those values; restrict this shortcut to exact built-in primitive types or handle enums before it.
        elif isinstance(v, (str, int, float, bool)) or v is None:
  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

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.

2 participants