Skip to content

Commit 63f3eee

Browse files
committed
issue python-jsonschema#158: Merge branch 'break_errloop' into 'split_unroll_scopes'
* Mark BreakLoopException as private. Although break_loop was not faster by itself, combined with the previous optimizations dropped even further the time: MAX FASTER x2!
2 parents f0c6f8f + d0609d9 commit 63f3eee

File tree

5 files changed

+878
-830
lines changed

5 files changed

+878
-830
lines changed

jsonschema/_validators.py

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

33
from jsonschema import _utils
4-
from jsonschema.exceptions import FormatError, ValidationError
4+
from jsonschema.exceptions import FormatError, ValidationError, _BreakLoopException
55
from jsonschema.compat import iteritems
66

77

@@ -196,6 +196,7 @@ def ref(validator, ref, instance, schema):
196196
with validator.resolver.resolving(ref) as resolved:
197197
for error in validator.descend(instance, resolved):
198198
yield error
199+
raise _BreakLoopException()
199200

200201

201202
def type_draft3(validator, types, instance, schema):

jsonschema/exceptions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ def __unicode__(self):
165165
if PY3:
166166
__str__ = __unicode__
167167

168+
class _BreakLoopException(Exception):
169+
pass
168170

169171
class ErrorTree(object):
170172
"""

jsonschema/tests/test_benchmarks.py

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ def test_V3_meta_schema(self):
5858
5959
278 runs in 2.00 sec
6060
ms/run: mean(7.17), std(0.56), MIN(6.50), MAX(10.51)
61+
286 runs in 2.00 sec
62+
ms/run: mean(6.98), std(0.35), MIN(6.50), MAX(9.50)
6163
6264
unroll_scopes (a22789a): Time @ Xeon 3.2GHz (x 1.19 faster)::
6365
@@ -69,10 +71,20 @@ def test_V3_meta_schema(self):
6971
290 runs in 2.00 sec
7072
ms/run: mean(6.88), std(0.66), MIN(6.00), MAX(12.00)
7173
72-
combine_untoll_split_scopes: Time @ Xeon 3.2GHz (x 1.25 faster)::
74+
combine_unroll_split_scopes (f0c6f8f): Time @ Xeon 3.2GHz (x 1.25 faster)::
7375
7476
347 runs in 2.00 sec
7577
ms/run: mean(5.75), std(0.67), MIN(5.00), MAX(11.50)
78+
79+
break_loop (d0609d9): Time @ Xeon 3.2GHz::
80+
81+
283 runs in 2.00 sec
82+
ms/run: mean(7.05), std(0.28), MIN(6.50), MAX(9.50)
83+
84+
break_unroll_defrag: Time @ Xeon 3.2GHz (x 1.33 faster)::
85+
86+
371 runs in 2.00 sec
87+
ms/run: mean(5.39), std(0.27), MIN(5.00), MAX(6.50)
7688
"""
7789

7890
stats = []
@@ -93,6 +105,8 @@ def test_V4_meta_schema(self):
93105
94106
164 runs in 2.00 sec
95107
ms/run: mean(12.15), std(1.36), MIN(11.01), MAX(21.02)
108+
174 runs in 2.01 sec
109+
ms/run: mean(11.47), std(0.36), MIN(11.00), MAX(13.00)
96110
97111
unroll_scopes (a22789a): Time @ Xeon 3.2GHz (x 1.09 faster)::
98112
@@ -104,10 +118,20 @@ def test_V4_meta_schema(self):
104118
191 runs in 2.01 sec
105119
ms/run: mean(10.47), std(0.81), MIN(9.50), MAX(14.00)
106120
107-
combine_untoll_split_scopes: Time @ Xeon 3.2GHz (x 1.38 faster)::
121+
combine_unroll_split_scopes (f0c6f8f): Time @ Xeon 3.2GHz (x 1.38 faster)::
108122
109123
228 runs in 2.01 sec
110124
ms/run: mean(8.77), std(0.74), MIN(8.00), MAX(12.50)
125+
126+
break_loop (d0609d9): Time @ Xeon 3.2GHz::
127+
128+
173 runs in 2.01 sec
129+
ms/run: mean(11.53), std(0.28), MIN(11.00), MAX(13.00)
130+
131+
break_unroll_defrag: Time @ Xeon 3.2GHz (x 1.45 faster)::
132+
133+
238 runs in 2.00 sec
134+
ms/run: mean(8.38), std(0.28), MIN(8.00), MAX(9.50)
111135
"""
112136

113137
stats = []
@@ -128,6 +152,8 @@ def test_both_meta_schemas(self):
128152
129153
104 runs in 2.01 sec
130154
ms/run: mean(19.13), std(1.12), MIN(18.01), MAX(23.02)
155+
108 runs in 2.00 sec
156+
ms/run: mean(18.38), std(0.35), MIN(18.00), MAX(19.50)
131157
132158
unroll_scopes (a22789a): Time @ Xeon 3.2GHz (x 1.13 faster)::
133159
@@ -139,10 +165,20 @@ def test_both_meta_schemas(self):
139165
115 runs in 2.00 sec
140166
ms/run: mean(17.24), std(1.24), MIN(16.00), MAX(24.51)
141167
142-
combine_untoll_split_scopes: Time @ Xeon 3.2GHz (x 1.32 faster)::
168+
combine_unroll_split_scopes (f0c6f8f): Time @ Xeon 3.2GHz (x 1.32 faster)::
143169
144170
138 runs in 2.01 sec
145171
ms/run: mean(14.47), std(1.03), MIN(13.50), MAX(19.50)
172+
173+
break_loop (d0609d9): Time @ Xeon 3.2GHz::
174+
175+
107 runs in 2.01 sec
176+
ms/run: mean(18.62), std(0.38), MIN(18.00), MAX(20.00)
177+
178+
break_unroll_defrag: Time @ Xeon 3.2GHz (x 1.37 faster)::
179+
180+
143 runs in 2.01 sec
181+
ms/run: mean(13.93), std(0.41), MIN(13.50), MAX(15.50)
146182
"""
147183

148184
v_classes = [Draft3Validator, Draft4Validator]
@@ -165,6 +201,8 @@ def test_ref_model(self):
165201
166202
16 runs in 2.00 sec
167203
ms/run: mean(117.80), std(4.32), MIN(113.09), MAX(127.60)
204+
18 runs in 2.07 sec
205+
ms/run: mean(109.21), std(1.33), MIN(107.52), MAX(112.52)
168206
169207
unroll_scopes (a22789a): Time @ Xeon 3.2GHz (x 1.43 faster)::
170208
@@ -176,10 +214,20 @@ def test_ref_model(self):
176214
19 runs in 2.10 sec
177215
ms/run: mean(105.07), std(2.45), MIN(102.02), MAX(109.02)
178216
179-
combine_untoll_split_scopes: Time @ Xeon 3.2GHz (x 1.80 faster)::
217+
combine_unroll_split_scopes (f0c6f8f): Time @ Xeon 3.2GHz (x 1.80 faster)::
180218
181219
30 runs in 2.03 sec
182220
ms/run: mean(65.35), std(4.83), MIN(60.01), MAX(82.02)
221+
222+
break_loop (d0609d9): Time @ Xeon 3.2GHz::
223+
224+
18 runs in 2.09 sec
225+
ms/run: mean(109.97), std(0.80), MIN(109.02), MAX(112.02)
226+
227+
break_unroll_defrag: Time @ Xeon 3.2GHz (x 2.00 faster)::
228+
229+
33 runs in 2.01 sec
230+
ms/run: mean(59.03), std(0.74), MIN(58.01), MAX(62.01)
183231
"""
184232

185233
stats = []

0 commit comments

Comments
 (0)