| 1019 | _BATCHSIZE = 1000 |
| 1020 | |
| 1021 | def _batch_appends(self, items, obj): |
| 1022 | # Helper to batch up APPENDS sequences |
| 1023 | save = self.save |
| 1024 | write = self.write |
| 1025 | |
| 1026 | if not self.bin: |
| 1027 | for i, x in enumerate(items): |
| 1028 | try: |
| 1029 | save(x) |
| 1030 | except BaseException as exc: |
| 1031 | exc.add_note(f'when serializing {_T(obj)} item {i}') |
| 1032 | raise |
| 1033 | write(APPEND) |
| 1034 | return |
| 1035 | |
| 1036 | start = 0 |
| 1037 | for batch in batched(items, self._BATCHSIZE): |
| 1038 | batch_len = len(batch) |
| 1039 | if batch_len != 1: |
| 1040 | write(MARK) |
| 1041 | for i, x in enumerate(batch, start): |
| 1042 | try: |
| 1043 | save(x) |
| 1044 | except BaseException as exc: |
| 1045 | exc.add_note(f'when serializing {_T(obj)} item {i}') |
| 1046 | raise |
| 1047 | write(APPENDS) |
| 1048 | else: |
| 1049 | try: |
| 1050 | save(batch[0]) |
| 1051 | except BaseException as exc: |
| 1052 | exc.add_note(f'when serializing {_T(obj)} item {start}') |
| 1053 | raise |
| 1054 | write(APPEND) |
| 1055 | start += batch_len |
| 1056 | |
| 1057 | def save_dict(self, obj): |
| 1058 | if self.bin: |