From d96dcad7d810055a40f859c4744f7aafbac1455f Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Mon, 16 Aug 2021 13:38:14 -0400 Subject: [PATCH] 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. --- RELEASES.md | 5 +++++ tamer/src/obj/xmlo/reader/mod.rs | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/RELEASES.md b/RELEASES.md index 284b18aa..b355367d 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -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) diff --git a/tamer/src/obj/xmlo/reader/mod.rs b/tamer/src/obj/xmlo/reader/mod.rs index 9b24477c..318bfc8c 100644 --- a/tamer/src/obj/xmlo/reader/mod.rs +++ b/tamer/src/obj/xmlo/reader/mod.rs @@ -250,6 +250,11 @@ where /// /// TODO: Augment failures with context pub fn read_event<'a>(&mut self) -> XmloResult> { + // 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