MCPcopy
hub / github.com/reflex-dev/reflex / _check_state_size

Method _check_state_size

reflex/state.py:2090–2116  ·  view source on GitHub ↗

Print a warning when the state is too large. Args: pickle_state_size: The size of the pickled state. Raises: StateTooLargeError: If the state is too large.

(
        self,
        pickle_state_size: int,
    )

Source from the content-addressed store, hash-verified

2088 object.__setattr__(self, key, value)
2089
2090 def _check_state_size(
2091 self,
2092 pickle_state_size: int,
2093 ):
2094 """Print a warning when the state is too large.
2095
2096 Args:
2097 pickle_state_size: The size of the pickled state.
2098
2099 Raises:
2100 StateTooLargeError: If the state is too large.
2101 """
2102 state_full_name = self.get_full_name()
2103 if (
2104 state_full_name not in _WARNED_ABOUT_STATE_SIZE
2105 and pickle_state_size > TOO_LARGE_SERIALIZED_STATE
2106 and self.substates
2107 ):
2108 msg = (
2109 f"State {state_full_name} serializes to {pickle_state_size} bytes "
2110 + "which may present performance issues. Consider reducing the size of this state."
2111 )
2112 if environment.REFLEX_PERF_MODE.get() == PerformanceMode.WARN:
2113 console.warn(msg)
2114 elif environment.REFLEX_PERF_MODE.get() == PerformanceMode.RAISE:
2115 raise StateTooLargeError(msg)
2116 _WARNED_ABOUT_STATE_SIZE.add(state_full_name)
2117
2118 @classmethod
2119 @functools.lru_cache

Callers 1

_serializeMethod · 0.95

Calls 3

get_full_nameMethod · 0.95
StateTooLargeErrorClass · 0.90
getMethod · 0.45

Tested by

no test coverage detected