Skip to content

Commit

Permalink
perf: faster startup (#55)
Browse files Browse the repository at this point in the history
### Summary of Changes

Lazily run imports to improve startup time of the runner.
  • Loading branch information
lars-reimann authored Feb 25, 2024
1 parent e0332fc commit a3fbe24
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/safeds_runner/server/_json_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
import math
from typing import Any

from safeds.data.image.containers import Image
from safeds.data.tabular.containers import Table


class SafeDsEncoder(json.JSONEncoder):
"""JSON Encoder for custom Safe-DS types."""
Expand All @@ -30,6 +27,10 @@ def default(self, o: Any) -> Any:
Any
The passed object represented in a way that is serializable to JSON.
"""
# Moving these imports to the top drastically increases startup time
from safeds.data.image.containers import Image
from safeds.data.tabular.containers import Table

if isinstance(o, Table):
dict_with_nan_infinity = o.to_dict()
# Convert NaN / Infinity to None, as the JSON encoder generates invalid JSON otherwise
Expand Down

0 comments on commit a3fbe24

Please sign in to comment.