tamer: tameld: Reduce peak memory usage

This clears the buffers used by quick_xml, which was apparently forgotten
during initial development (I think I expected it to re-use the previously
allocated space automatically).

This has significant effects in some cases.  For example, one of our UI
builds drops from ~9KiB to ~5KiB peak memory usage.  Other builds for larger
suppliers are only slightly effected because of some of their massive
fragments.
main
Mike Gerwitz 2021-08-16 13:38:14 -04:00
parent ce233ac01d
commit d96dcad7d8
2 changed files with 10 additions and 0 deletions

View File

@ -24,6 +24,11 @@ Linker
------
- Remove exception for input map dependency processing (now that compiler no
longer emits such a dependency).
- Reduce peak memory usage by clearing buffer of `xmlo` reader between
events.
- How effective this is varies depending on the size of individual
entities within the XML document. In some cases, it can reduce peak
memory usage by half.
v18.0.3 (2021-07-21)

View File

@ -250,6 +250,11 @@ where
///
/// TODO: Augment failures with context
pub fn read_event<'a>(&mut self) -> XmloResult<XmloEvent<Ix>> {
// Just to cut down on peak memory usage, cleaning up after a
// previous run. This does not affect behavior.
self.buffer.clear();
self.sub_buffer.clear();
let event = self.reader.read_event(&mut self.buffer)?;
// Ensure that the first encountered node is something we expect