Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improved memory consumption for PresentationBuilder.PublishSlides #44

Merged

Conversation

f1nzer
Copy link
Contributor

@f1nzer f1nzer commented Dec 16, 2021

The improvement consists of two parts:

  1. Slide's title is retrieved from the generated slide rather than from the original one. There is no need to load and parse the content for the slide twice (once for the original slide and once for the new one during generation)
  2. The source XDoc for generating a slide is retrieved using slide.GetXDocument(), then it saves the XDocument in the .Annotation<XDocument>(). So, there is a direct reference from the original slide to the new one. That's why the generated slides are not collected by GC (they were collected after the original PresentationDocument disposal).

You can see the difference in memory results below (execution is paused before srcDoc disposal).

Code:

[Fact]
public void MemoryTest()
{
    var sourcePath = @"TESTFILE.pptx";
    var openSettings = new OpenSettings { AutoSave = false };

    using (var srcStream = File.Open(sourcePath, FileMode.Open))
    using (var srcDoc = OpenXmlExtensions.OpenPresentation(srcStream, false, openSettings))
    {
        var index = 1;
        foreach (var slide in PresentationBuilder.PublishSlides(srcDoc, sourcePath))
        {
            index++;
        }
    }
}

Before:
devenv_m3dFruyAZF

After:
devenv_0nBlFZiHFo

@sergey-tihon sergey-tihon merged commit d8d931a into sergey-tihon:master Dec 16, 2021
@sergey-tihon
Copy link
Owner

Perfect! Thank you @f1nzer !
Released as v1.8.2

@f1nzer f1nzer deleted the feat/pptx-split-optimization branch November 16, 2022 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants