Skip to content

Commit 4d1c86d

Browse files
authored
check against classvar for fast case (#5947)
* check against classvar for fast case * also have one for setattr
1 parent e5d3552 commit 4d1c86d

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

reflex/state.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,21 @@ async def _resolve_delta(delta: Delta) -> Delta:
308308

309309
all_base_state_classes: dict[str, None] = {}
310310

311+
CLASS_VAR_NAMES = frozenset({
312+
"vars",
313+
"base_vars",
314+
"computed_vars",
315+
"inherited_vars",
316+
"backend_vars",
317+
"inherited_backend_vars",
318+
"event_handlers",
319+
"class_subclasses",
320+
"_var_dependencies",
321+
"_always_dirty_computed_vars",
322+
"_always_dirty_substates",
323+
"_potentially_dirty_states",
324+
})
325+
311326

312327
class BaseState(EvenMoreBasicBaseState):
313328
"""The state of the app."""
@@ -1320,7 +1335,7 @@ def __getattribute__(self, name: str) -> Any:
13201335
The value of the var.
13211336
"""
13221337
# Fast path for dunder
1323-
if name.startswith("__"):
1338+
if name.startswith("__") or name in CLASS_VAR_NAMES:
13241339
return super().__getattribute__(name)
13251340

13261341
# For now, handle router_data updates as a special case.
@@ -1378,6 +1393,11 @@ def __setattr__(self, name: str, value: Any):
13781393
Raises:
13791394
SetUndefinedStateVarError: If a value of a var is set without first defining it.
13801395
"""
1396+
if name.startswith("__") or name in CLASS_VAR_NAMES:
1397+
# Fast path for dunder and class vars
1398+
object.__setattr__(self, name, value)
1399+
return
1400+
13811401
if isinstance(value, MutableProxy):
13821402
# unwrap proxy objects when assigning back to the state
13831403
value = value.__wrapped__

0 commit comments

Comments
 (0)