Skip to content

Commit

Permalink
chore: Disable JIT cache by default
Browse files Browse the repository at this point in the history
  • Loading branch information
mLupine committed Oct 9, 2023
1 parent 9d1a77a commit f6458a5
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions deepfriedmarshmallow/serializer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

from deepfriedmarshmallow.jit import (
JitContext,
generate_deserialize_method,
Expand Down Expand Up @@ -29,23 +31,29 @@ def __call__(self, obj, many=False, **kwargs): # noqa: FBT002
return result

def _ensure_jit_method(self):
if self._jit_method is None:
if "_dfm_jit_cache" not in globals():
globals()["_dfm_jit_cache"] = {}

cache_key = (
self._schema.__class__.__name__,
self._schema.many,
id(self._schema.__class__),
self._method.__name__,
)
if cache_key not in globals()["_dfm_jit_cache"]:
logger.debug(f"Generating JIT method {cache_key=}")
globals()["_dfm_jit_cache"][cache_key] = self.generate_jit_method(self._schema, JitContext())
else:
logger.debug(f"Using cached JIT method {cache_key}")

self._jit_method = globals()["_dfm_jit_cache"][cache_key]
if self._jit_method is not None:
return

if os.getenv("DFM_CACHE_JIT", "false").lower() not in ("true", "1", "yes", "y", "on"):
self._jit_method = self.generate_jit_method(self._schema, JitContext())
return

if "_dfm_jit_cache" not in globals():
globals()["_dfm_jit_cache"] = {}

cache_key = (
self._schema.__class__.__name__,
self._schema.many,
id(self._schema.__class__),
self._method.__name__,
)
if cache_key not in globals()["_dfm_jit_cache"]:
logger.debug(f"Generating JIT method {cache_key=}")
globals()["_dfm_jit_cache"][cache_key] = self.generate_jit_method(self._schema, JitContext())
else:
logger.debug(f"Using cached JIT method {cache_key}")

self._jit_method = globals()["_dfm_jit_cache"][cache_key]

def generate_jit_method(self, schema, context):
raise NotImplementedError
Expand Down

0 comments on commit f6458a5

Please sign in to comment.