Skip to content

Commit 51aa50a

Browse files
⚡️ Speed up function _operation by 80%
Here is an optimized version of your function. The largest bottleneck identified is from the unnecessary use of `dict(**kwargs)`, which creates a new dictionary from kwargs, but since `kwargs` is already a dictionary, this is just a redundant and potentially slower operation. You can use `kwargs` directly, which saves both CPU and memory. **Explanation:** - Returning `kwargs` as is avoids an unnecessary dictionary copy, achieving lower runtime and memory usage. - The return value is unchanged: the `"params"` entry will be the dictionary of arguments supplied via `**kwargs`. This is the fastest and leanest way to implement your functionality per the profiling results.
1 parent bb13521 commit 51aa50a

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

dash/_patch.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33

44
def _operation(name, location, **kwargs):
5-
return {"operation": name, "location": location, "params": dict(**kwargs)}
5+
# No need to wrap kwargs in dict(), it's already a dict.
6+
return {"operation": name, "location": location, "params": kwargs}
67

78

89
_noop = object()

0 commit comments

Comments
 (0)