Skip to content

Commit

Permalink
Don't let templates be mutated (#232)
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti authored Nov 26, 2024
1 parent 15794ac commit 75d267a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/compiler/compile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ auto compile(const sourcemeta::jsontoolkit::JSON &schema,
const sourcemeta::jsontoolkit::SchemaWalker &walker,
const sourcemeta::jsontoolkit::SchemaResolver &resolver,
const Compiler &compiler, const Mode mode,
const std::optional<std::string> &default_dialect) -> Template {
const std::optional<std::string> &default_dialect)
-> const Template {
assert(is_schema(schema));

// Make sure the input schema is bundled, otherwise we won't be able to
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/include/sourcemeta/blaze/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ compile(const sourcemeta::jsontoolkit::JSON &schema,
const sourcemeta::jsontoolkit::SchemaResolver &resolver,
const Compiler &compiler, const Mode mode = Mode::FastValidation,
const std::optional<std::string> &default_dialect = std::nullopt)
-> Template;
-> const Template;

/// @ingroup compiler
///
Expand Down

5 comments on commit 75d267a

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark (macos/llvm)

Benchmark suite Current: 75d267a Previous: 15794ac Ratio
Compiler_Draft6_AdaptiveCard 45419397291.999985 ns/iter 49946578790.99992 ns/iter 0.91
Compiler_2019_09_OMC_JSON_V2 8390046165.999933 ns/iter 8914620917.000093 ns/iter 0.94
Evaluator_Draft4_Meta_1_No_Callback 278.7450326636192 ns/iter 308.6802138668829 ns/iter 0.90
Evaluator_Draft4_Required_Properties 377.29681523277213 ns/iter 373.85108898163867 ns/iter 1.01
Evaluator_Draft4_Many_Optional_Properties_Minimal_Match 25.519465096963067 ns/iter 22.527039209473667 ns/iter 1.13
Evaluator_Draft4_Few_Optional_Properties_Minimal_Match 11.77855819066616 ns/iter 11.7258911171376 ns/iter 1.00
Evaluator_Draft4_Items_Schema 365.78231938677067 ns/iter 377.9097161121498 ns/iter 0.97
Evaluator_Draft4_Nested_Object 3.734461638426351 ns/iter 3.586261853053851 ns/iter 1.04
Evaluator_Draft4_Properties_Triad_Optional 987.387432503378 ns/iter 975.5260808769045 ns/iter 1.01
Evaluator_Draft4_Properties_Triad_Closed 752.901545953028 ns/iter 756.7258057546345 ns/iter 0.99
Evaluator_Draft4_Properties_Triad_Required 981.4127320691945 ns/iter 936.0327745381481 ns/iter 1.05
Evaluator_Draft4_Properties_Closed 91.1221220716041 ns/iter 104.02748389853835 ns/iter 0.88
Evaluator_Draft4_Non_Recursive_Ref 12.593034438286134 ns/iter 12.237467215841638 ns/iter 1.03
Evaluator_Draft4_Pattern_Properties_True 241.74909041461245 ns/iter 205.66833019861417 ns/iter 1.18
Evaluator_Draft4_Ref_To_Single_Property 13.581110999411523 ns/iter 13.830132275922725 ns/iter 0.98
Evaluator_Draft4_Additional_Properties_Type 29.205804768792376 ns/iter 23.858012559860562 ns/iter 1.22
Evaluator_Draft4_Nested_Oneof 82.97203254009769 ns/iter 80.1958973498905 ns/iter 1.03
Evaluator_Draft4_Long_Enum 34.114750316791024 ns/iter 32.25102417900638 ns/iter 1.06
Evaluator_Draft4_Type_Object 7.588790412249442 ns/iter 7.280338342650205 ns/iter 1.04
Evaluator_Draft6_Property_Names 159.77966985165762 ns/iter 149.07100256562708 ns/iter 1.07
Evaluator_Draft7_If_Then_Else 33.39973497255534 ns/iter 29.890551962234568 ns/iter 1.12
Evaluator_Draft7_Vercel_1 85766.67576419387 ns/iter 85516.34313832954 ns/iter 1.00
Evaluator_Draft7_Helm_Chart_Lock_1 269.8595919175204 ns/iter 262.7379810929034 ns/iter 1.03
Evaluator_2019_09_Unevaluated_Properties 162.62774645128792 ns/iter 165.3209332408945 ns/iter 0.98
Evaluator_2019_09_OMC_JSON_V2_1 2625.2438112230557 ns/iter 2653.4431441769193 ns/iter 0.99
Evaluator_2020_12_Dynamic_Ref 558.3831864583581 ns/iter 585.3940214751035 ns/iter 0.95

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark (linux/llvm)

Benchmark suite Current: 75d267a Previous: 15794ac Ratio
Compiler_Draft6_AdaptiveCard 53213217113.00004 ns/iter 52596647215.000015 ns/iter 1.01
Compiler_2019_09_OMC_JSON_V2 10740453437.999975 ns/iter 10732114705.000015 ns/iter 1.00
Evaluator_Draft4_Meta_1_No_Callback 346.33626005609744 ns/iter 349.1302683175767 ns/iter 0.99
Evaluator_Draft4_Required_Properties 780.8963765261502 ns/iter 781.2493440253498 ns/iter 1.00
Evaluator_Draft4_Many_Optional_Properties_Minimal_Match 38.64111832717645 ns/iter 38.74335315069147 ns/iter 1.00
Evaluator_Draft4_Few_Optional_Properties_Minimal_Match 23.824180813678595 ns/iter 23.863158590734635 ns/iter 1.00
Evaluator_Draft4_Items_Schema 706.5408274355061 ns/iter 711.5523016790083 ns/iter 0.99
Evaluator_Draft4_Nested_Object 4.94632680561611 ns/iter 4.950449990484574 ns/iter 1.00
Evaluator_Draft4_Properties_Triad_Optional 1189.7751321741766 ns/iter 1178.1419044798483 ns/iter 1.01
Evaluator_Draft4_Properties_Triad_Closed 1034.2811774943489 ns/iter 999.0376626186643 ns/iter 1.04
Evaluator_Draft4_Properties_Triad_Required 1210.6758865073248 ns/iter 1199.8053102195113 ns/iter 1.01
Evaluator_Draft4_Properties_Closed 138.48123696495662 ns/iter 138.64914429733284 ns/iter 1.00
Evaluator_Draft4_Non_Recursive_Ref 29.38169268496525 ns/iter 29.42735654506712 ns/iter 1.00
Evaluator_Draft4_Pattern_Properties_True 261.27425145708156 ns/iter 271.9249893533992 ns/iter 0.96
Evaluator_Draft4_Ref_To_Single_Property 24.724996752358365 ns/iter 24.745506569238074 ns/iter 1.00
Evaluator_Draft4_Additional_Properties_Type 55.22491959948818 ns/iter 53.49152737228632 ns/iter 1.03
Evaluator_Draft4_Nested_Oneof 127.63343985667696 ns/iter 128.4833244559637 ns/iter 0.99
Evaluator_Draft4_Long_Enum 20.725795697370096 ns/iter 20.80211857838683 ns/iter 1.00
Evaluator_Draft4_Type_Object 11.747060412983457 ns/iter 11.756437466060573 ns/iter 1.00
Evaluator_Draft6_Property_Names 240.2907049419444 ns/iter 263.42705582144896 ns/iter 0.91
Evaluator_Draft7_If_Then_Else 57.20557607337699 ns/iter 57.23914213707676 ns/iter 1.00
Evaluator_Draft7_Vercel_1 92009.01803214356 ns/iter 90567.47058064266 ns/iter 1.02
Evaluator_Draft7_Helm_Chart_Lock_1 338.4438116474264 ns/iter 335.32070489104416 ns/iter 1.01
Evaluator_2019_09_Unevaluated_Properties 212.00327575783857 ns/iter 196.24135904005118 ns/iter 1.08
Evaluator_2019_09_OMC_JSON_V2_1 3278.772607308394 ns/iter 3290.414105576312 ns/iter 1.00
Evaluator_2020_12_Dynamic_Ref 873.9619795017551 ns/iter 891.6393124963471 ns/iter 0.98

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark (linux/gcc)

Benchmark suite Current: 75d267a Previous: 15794ac Ratio
Evaluator_2020_12_Dynamic_Ref 850.5121185581859 ns/iter 883.5200964840266 ns/iter 0.96
Evaluator_2019_09_Unevaluated_Properties 232.2555813652612 ns/iter 225.14198045635186 ns/iter 1.03
Evaluator_2019_09_OMC_JSON_V2_1 4790.2107975386225 ns/iter 4811.342066072549 ns/iter 1.00
Evaluator_Draft7_If_Then_Else 53.37426506176978 ns/iter 51.4393327341161 ns/iter 1.04
Evaluator_Draft7_Vercel_1 111950.6619245455 ns/iter 115254.1136909547 ns/iter 0.97
Evaluator_Draft7_Helm_Chart_Lock_1 503.5833440000488 ns/iter 470.11033113048325 ns/iter 1.07
Evaluator_Draft6_Property_Names 497.56727163061 ns/iter 499.94275721512486 ns/iter 1.00
Evaluator_Draft4_Meta_1_No_Callback 416.74850104344097 ns/iter 412.49999491009345 ns/iter 1.01
Evaluator_Draft4_Required_Properties 1649.0368524351454 ns/iter 1632.9123685190823 ns/iter 1.01
Evaluator_Draft4_Many_Optional_Properties_Minimal_Match 40.33675243882911 ns/iter 39.68732686318123 ns/iter 1.02
Evaluator_Draft4_Few_Optional_Properties_Minimal_Match 32.28797282069512 ns/iter 32.28600013575097 ns/iter 1.00
Evaluator_Draft4_Items_Schema 556.3867645051585 ns/iter 565.4331437222024 ns/iter 0.98
Evaluator_Draft4_Nested_Object 3.8344732590618484 ns/iter 3.8253503196846323 ns/iter 1.00
Evaluator_Draft4_Properties_Triad_Optional 1268.0638189588562 ns/iter 1190.164898459714 ns/iter 1.07
Evaluator_Draft4_Properties_Triad_Closed 985.7524218164965 ns/iter 997.2528955684999 ns/iter 0.99
Evaluator_Draft4_Properties_Triad_Required 1209.3032538755551 ns/iter 1229.0494432188416 ns/iter 0.98
Evaluator_Draft4_Properties_Closed 186.55655172339638 ns/iter 182.03043815125395 ns/iter 1.02
Evaluator_Draft4_Non_Recursive_Ref 53.13586959271967 ns/iter 52.93520362606419 ns/iter 1.00
Evaluator_Draft4_Pattern_Properties_True 333.4403895812474 ns/iter 330.73516777082864 ns/iter 1.01
Evaluator_Draft4_Ref_To_Single_Property 36.691599598824006 ns/iter 38.389985269472064 ns/iter 0.96
Evaluator_Draft4_Additional_Properties_Type 112.03108333076818 ns/iter 111.9084824357311 ns/iter 1.00
Evaluator_Draft4_Nested_Oneof 107.33751700288263 ns/iter 108.73700117076666 ns/iter 0.99
Evaluator_Draft4_Long_Enum 20.345015865980724 ns/iter 19.72666508031642 ns/iter 1.03
Evaluator_Draft4_Type_Object 10.01068874199368 ns/iter 9.97204156401507 ns/iter 1.00
Compiler_2019_09_OMC_JSON_V2 11226821831.999928 ns/iter 11179924231.999962 ns/iter 1.00
Compiler_Draft6_AdaptiveCard 61322249515.99994 ns/iter 61006595105.000084 ns/iter 1.01

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark (macos/gcc)

Benchmark suite Current: 75d267a Previous: 15794ac Ratio
Compiler_Draft6_AdaptiveCard 44087544918.0603 ns/iter 41129198789.59656 ns/iter 1.07
Compiler_2019_09_OMC_JSON_V2 9164417982.10144 ns/iter 8225801944.732666 ns/iter 1.11
Evaluator_Draft4_Meta_1_No_Callback 285.09794812672135 ns/iter 257.58601319135175 ns/iter 1.11
Evaluator_Draft4_Required_Properties 480.2908819153727 ns/iter 471.79513983578596 ns/iter 1.02
Evaluator_Draft4_Many_Optional_Properties_Minimal_Match 25.276343273397433 ns/iter 23.90894273493959 ns/iter 1.06
Evaluator_Draft4_Few_Optional_Properties_Minimal_Match 16.14775448675159 ns/iter 14.540692478590016 ns/iter 1.11
Evaluator_Draft4_Items_Schema 546.7431545257568 ns/iter 510.5067096047481 ns/iter 1.07
Evaluator_Draft4_Nested_Object 2.1152921773995703 ns/iter 2.056556938566998 ns/iter 1.03
Evaluator_Draft4_Properties_Triad_Optional 907.638403565608 ns/iter 873.342010168559 ns/iter 1.04
Evaluator_Draft4_Properties_Triad_Closed 761.6695792769988 ns/iter 742.0312007387284 ns/iter 1.03
Evaluator_Draft4_Properties_Triad_Required 961.0903686297481 ns/iter 880.8440682730054 ns/iter 1.09
Evaluator_Draft4_Properties_Closed 96.51475449479501 ns/iter 97.33752232215484 ns/iter 0.99
Evaluator_Draft4_Non_Recursive_Ref 20.539725658361142 ns/iter 19.534427852695423 ns/iter 1.05
Evaluator_Draft4_Pattern_Properties_True 246.29867883067587 ns/iter 229.71921964426303 ns/iter 1.07
Evaluator_Draft4_Ref_To_Single_Property 13.623447291608848 ns/iter 13.799581540295458 ns/iter 0.99
Evaluator_Draft4_Additional_Properties_Type 37.93784829597792 ns/iter 40.185513785556644 ns/iter 0.94
Evaluator_Draft4_Nested_Oneof 82.87727156783227 ns/iter 82.74066256726152 ns/iter 1.00
Evaluator_Draft4_Long_Enum 13.592838347147062 ns/iter 11.810682440283845 ns/iter 1.15
Evaluator_Draft4_Type_Object 6.892884302659078 ns/iter 6.1080276999281296 ns/iter 1.13
Evaluator_Draft6_Property_Names 209.06317044128676 ns/iter 189.2262064693968 ns/iter 1.10
Evaluator_Draft7_If_Then_Else 35.871056261624865 ns/iter 33.312644255230744 ns/iter 1.08
Evaluator_Draft7_Vercel_1 83502.19051164959 ns/iter 78284.43149090295 ns/iter 1.07
Evaluator_Draft7_Helm_Chart_Lock_1 261.2285554634366 ns/iter 229.82178611722068 ns/iter 1.14
Evaluator_2019_09_Unevaluated_Properties 181.1096729859428 ns/iter 151.62830578036196 ns/iter 1.19
Evaluator_2019_09_OMC_JSON_V2_1 2239.787246505278 ns/iter 2317.1213391024044 ns/iter 0.97
Evaluator_2020_12_Dynamic_Ref 570.1878863035072 ns/iter 583.7206702898075 ns/iter 0.98

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark (windows/msvc)

Benchmark suite Current: 75d267a Previous: 15794ac Ratio
Compiler_Draft6_AdaptiveCard 120178599899.99988 ns/iter 120135471400.00003 ns/iter 1.00
Compiler_2019_09_OMC_JSON_V2 24912561399.999958 ns/iter 25055662999.99998 ns/iter 0.99
Evaluator_Draft4_Meta_1_No_Callback 434.6670625000115 ns/iter 427.3898749999461 ns/iter 1.02
Evaluator_Draft4_Required_Properties 747.1449776786138 ns/iter 735.6239285714747 ns/iter 1.02
Evaluator_Draft4_Many_Optional_Properties_Minimal_Match 35.831191501127414 ns/iter 35.82281806368304 ns/iter 1.00
Evaluator_Draft4_Few_Optional_Properties_Minimal_Match 22.209759375002136 ns/iter 22.049090624999934 ns/iter 1.01
Evaluator_Draft4_Items_Schema 606.3391964285561 ns/iter 637.8064285714556 ns/iter 0.95
Evaluator_Draft4_Nested_Object 4.043394069719562 ns/iter 4.043278578648681 ns/iter 1.00
Evaluator_Draft4_Properties_Triad_Optional 1680.8936511875634 ns/iter 1684.0368303573225 ns/iter 1.00
Evaluator_Draft4_Properties_Triad_Closed 1400.2529239943192 ns/iter 1387.1920816106715 ns/iter 1.01
Evaluator_Draft4_Properties_Triad_Required 1718.1823985387466 ns/iter 1714.687936592852 ns/iter 1.00
Evaluator_Draft4_Properties_Closed 133.8255542934873 ns/iter 135.65494642857547 ns/iter 0.99
Evaluator_Draft4_Non_Recursive_Ref 15.480305803572087 ns/iter 15.752611607141429 ns/iter 0.98
Evaluator_Draft4_Pattern_Properties_True 241.00915836947814 ns/iter 242.2728077820509 ns/iter 0.99
Evaluator_Draft4_Ref_To_Single_Property 23.517408219670255 ns/iter 23.461077863158227 ns/iter 1.00
Evaluator_Draft4_Additional_Properties_Type 30.97704910714023 ns/iter 31.10738575390855 ns/iter 1.00
Evaluator_Draft4_Nested_Oneof 131.26426785715597 ns/iter 129.61158928571794 ns/iter 1.01
Evaluator_Draft4_Long_Enum 21.193116801694337 ns/iter 21.153331249998075 ns/iter 1.00
Evaluator_Draft4_Type_Object 8.478542410715407 ns/iter 8.722830764631325 ns/iter 0.97
Evaluator_Draft6_Property_Names 430.01050000000873 ns/iter 414.2503788280656 ns/iter 1.04
Evaluator_Draft7_If_Then_Else 48.258732142849276 ns/iter 48.42375108088557 ns/iter 1.00
Evaluator_Draft7_Vercel_1 109954.90624999606 ns/iter 108300.23214286451 ns/iter 1.02
Evaluator_Draft7_Helm_Chart_Lock_1 344.40244443782467 ns/iter 340.93334983336257 ns/iter 1.01
Evaluator_2019_09_Unevaluated_Properties 438.24700000001826 ns/iter 421.928161908428 ns/iter 1.04
Evaluator_2019_09_OMC_JSON_V2_1 4275.809698299334 ns/iter 4138.71364343053 ns/iter 1.03
Evaluator_2020_12_Dynamic_Ref 1415.2507744415711 ns/iter 1401.9514723431184 ns/iter 1.01

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.