Free Support Forum - aspose.com

Pptx Merging extremely slow

I am starting with a blank presentation and then merging specific slides from multiple ppts into the blank one. It approximately takes 8-10 seconds for merging 1 slide.

Java Configuration:
java version “15.0.2” 2021-01-19
Java™ SE Runtime Environment (build 15.0.2+7-27)
Java HotSpot™ 64-Bit Server VM (build 15.0.2+7-27, mixed mode, sharing)

Aspose Configuration:
aspose-slides-21.2-jdk16

System Configuration:
OS: Windows 10
RAM: 8GB
Storage: 1TB

I have performed an exhaustive time analysis and it either takes around 10-15 seconds in creating the presentation object or in cloning the slide.

p_new = new Presentation();
SlideCollection slds = p_new.getSlides();
slds.addClone(p.getSlides().get_Item(v.get(i)));

@Apurva_Dani,
Welcome to our community! Thank you for the issue description. To my regret, I cannot use your code example containing the unknown symbols (p, v, i). Could you please share a comprehensive code snippet for checking the issue?

Please find the entire code below. The slowness in merging is present irrespective of the deck I use.

package aspose20;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import java.util.stream.IntStream;

import com.aspose.slides.Presentation;
import com.aspose.slides.SaveFormat;
import com.aspose.slides.ISlideCollection;

public class MergeSlide {
public static void main(String args[]) throws IOException {
System.out.println(“Merging Started!”);
Presentation p_new = new Presentation();
ISlideCollection slds = p_new.getSlides();

   //Any File location
   String file1 = "C:\\data\\deck1.pptx";
   String file2 = "C:\\data\\deck2.pptx";
   String[] inputs = {file1, file2};

// Index of slides to merge
    int deck1[] = new int[]{75, 17};
    int deck2[] = new int[]{15, 6}
    int [][] pptarr = {deck1, deck2};
    boolean test;
    long startTimefi = System.nanoTime();
    for(int p_no = 0; p_no < inputs.length; p_no++) {
	System.out.println(inputs[p_no]);
	long startTime = System.nanoTime();
	Presentation p = new Presentation(inputs[p_no]);
    long endTime = System.nanoTime();
   System.out.println("Reading "+TimeUnit.SECONDS.convert((endTime - startTime), TimeUnit.NANOSECONDS) + " s"); 
for (int index = 0; index< p.getSlides().size(); index = index+1) {
	
             // Merge slides from source to target
	final Integer innersc = new Integer(index);
	// Check if this slide is to be merged
            test  = IntStream.of(pptarr[p_no]).anyMatch(x -> x == innersc);
	if(test){
	startTime = System.nanoTime();
	slds.addClone(p.getSlides().get_Item(index));
	endTime = System.nanoTime();
	System.out.println("Merging "+TimeUnit.SECONDS.convert((endTime - startTime), TimeUnit.NANOSECONDS) + " s"); 
	}
}

}
long endTimefi = System.nanoTime();
System.out.println("Took “+TimeUnit.SECONDS.convert((endTimefi - startTimefi), TimeUnit.NANOSECONDS) + " s”);
// Save the presentation
p_new.save(“merged-presentation.pptx”, SaveFormat.Pptx);
System.out.println(“Merging Done!” + p_new.getSlides().size());

}
}

@Apurva_Dani,
Thank you for the code example. It will take me a while to investigate the issue. Thank you for your patience.

@Apurva_Dani,
Please share your test files (deck1.pptx and deck2.pptx).

Please find the decks over here:

Few points to note:

  1. It works slow irrespective of the deck being used.
  2. I ran it on AWS t2.micro ec2 instance and it works pretty fast, bringing down 10 seconds per slide to around 3.5 seconds per slide on an average.

@Apurva_Dani,
Thank you for the file samples. I reproduced the problem and received the same results for some slides. I have logged the issue in our tracking system with ID SLIDESJAVA-38482 for further investigation. You will be notified about any progress.

@Apurva_Dani,
Our development team has investigated the issue. This behavior occurs when the first slide is loaded because we are loading internal caches, etc. Please take a look at the following experimental results on our end:

Merging slide 75: 7 s
Merging slide 75: 0 s
Merging slide 75: 1 s
Merging slide 17: 1 s
Merging slide 17: 1 s

As you can see, when loading the slide a second time, the timing has greatly improved. Our development team investigated our code and found no bottlenecks that could be improved.