Skip to content

Commit 040cb8a

Browse files
committed
Limit the size of stream outputs to diff
This prevents large text outputs from taking up a lot of time in comparison. As the value of very large outputs is low, the impact on performance should be worth the improved performance.
1 parent 0f0a90a commit 040cb8a

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

nbdime/diffing/notebooks.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
re_pointer = re.compile(r"0x[a-f0-9]{8,16}", re.IGNORECASE)
4141

4242
TEXT_MIMEDATA_MAX_COMPARE_LENGTH = 10000
43+
STREAM_MAX_COMPARE_LENGTH = 1000
4344

4445

4546
# List of mimes we can diff recursively
@@ -139,7 +140,7 @@ def _compare_mimedata(mimetype, x, y, comp_text, comp_base64):
139140
# TODO: Compare binary images?
140141
#if mimetype.startswith("image/"):
141142
if isinstance(x, string_types) and isinstance(y, string_types):
142-
_compare_mimedata_strings(x, y, comp_text, comp_base64)
143+
return _compare_mimedata_strings(x, y, comp_text, comp_base64)
143144
# Fallback to exactly equal
144145
return x == y
145146

@@ -228,7 +229,7 @@ def compare_output_approximate(x, y):
228229
if ot == "stream":
229230
if x["name"] != y["name"]:
230231
return False
231-
if not compare_strings_approximate(x["text"], y["text"]):
232+
if not compare_strings_approximate(x["text"], y["text"], maxlen=STREAM_MAX_COMPARE_LENGTH):
232233
return False
233234
handled.update(("name", "text"))
234235

0 commit comments

Comments
 (0)