Commit 4f9d972
Add modify operation to ExtensionFieldValueSet.
During decoding, modifications are frequently made to the extension
values in ExtensionFieldValueSet. In particular for repeated extensions,
these modifications include modifications to copy-on-write data types.
Because the _modify accessor hasn't been standardised yet,
ExtensionFieldValueSet implements get/set only, forcing a modification
of existing data to be done by a get/set pair. This will always emit a
copy-on-write operation.
The result of the above is that decoding repeated extensions is a
quadratic operation, making it diabolically slow. oss-fuzz caught this
behaviour.
This patch adds a non-API modify function to ExtensionFieldValueSet and
uses it on all decoding paths. This code simply encapsulates a somewhat
delicate function invocation that manages to convince the Swift compiler
to use Dictionary's _modify accessor for the underlying operation. The
result is that the oss-fuzz sample runtime decreases from 140s to 5s on
my machine.
This patch will likely have miscellaneous performance improvements
across the board. It adds the oss-fuzz case for regression purposes as
well.1 parent 3a4b54d commit 4f9d972
File tree
5 files changed
+32
-35
lines changed- FuzzTesting/FailCases
- Sources/SwiftProtobuf
5 files changed
+32
-35
lines changedBinary file not shown.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1110 | 1110 | | |
1111 | 1111 | | |
1112 | 1112 | | |
1113 | | - | |
1114 | | - | |
1115 | | - | |
1116 | | - | |
1117 | | - | |
1118 | | - | |
1119 | | - | |
1120 | | - | |
1121 | | - | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
1122 | 1117 | | |
1123 | | - | |
| 1118 | + | |
1124 | 1119 | | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
1125 | 1123 | | |
1126 | 1124 | | |
1127 | 1125 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
81 | 87 | | |
82 | 88 | | |
83 | 89 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
724 | 724 | | |
725 | 725 | | |
726 | 726 | | |
727 | | - | |
728 | | - | |
729 | | - | |
730 | | - | |
731 | | - | |
732 | | - | |
733 | | - | |
734 | | - | |
735 | | - | |
736 | | - | |
737 | | - | |
738 | | - | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
739 | 733 | | |
740 | 734 | | |
741 | 735 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
708 | 708 | | |
709 | 709 | | |
710 | 710 | | |
711 | | - | |
712 | | - | |
713 | | - | |
714 | | - | |
715 | | - | |
716 | | - | |
717 | | - | |
718 | | - | |
719 | | - | |
720 | | - | |
721 | | - | |
722 | | - | |
723 | | - | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
724 | 723 | | |
725 | 724 | | |
726 | 725 | | |
| |||
0 commit comments