Skip to content

Commit 93d09c2

Browse files
vthemelismartinRenou
authored andcommitted
Major performance improvement
The change should be a no-op in terms of what the function that I changed returns. The obj argument of this recursive function is not actually used anywhere --it only appears in the recursive call and not at the base cases. `str(obj)` is a very expensive operation that we end up needlessly going through for O(rows) operations while initialising a DataGrid. This change significantly improves performance for me: Initialising a DataGrid for a DataFrame of 30k rows goes from 2.4s to 0.4s. Signed-off-by: Vasilis Themelis <[email protected]>
1 parent 70da430 commit 93d09c2

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

ipydatagrid/datagrid.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,11 @@ def _get_num_rows(self):
165165

166166

167167
# modified from ipywidgets original
168-
def _data_to_json(x, obj):
168+
def _data_to_json(x, _obj):
169169
if isinstance(x, dict):
170-
return {str(k): _data_to_json(v, obj) for k, v in x.items()}
170+
return {str(k): _data_to_json(v, _obj) for k, v in x.items()}
171171
elif isinstance(x, (list, tuple)):
172-
return [_data_to_json(v, str(obj)) for v in x]
172+
return [_data_to_json(v, _obj) for v in x]
173173
else:
174174
if isinstance(x, (float, int)):
175175
if np.isnan(x):

0 commit comments

Comments
 (0)