[GSOC 2023] Performance Optimization

Final Report

Weekly Reports: [GSOC 2023] Performance Optimization

Summary

During the Google Summer of Code 2023 program, I worked on the “Performance Optimization” project for Synfig. This project aimed to enhance the rendering speed of Synfig. Below is a summary of my progress, challenges, and plans for future work.

Pull Requests

Rendering Documentation(#104): In this PR, I wrote documentation explaining the rendering code of Synfig. The goal was to make it easier for newer developers to get started. It is ready to be merged.

Split Optimizer(#3112): This PR was me experimenting with split optimizer. I tried different methods of splitting the rendering to improve the rendering speed. There were some issues faced, like contour rendering overlaps at borders and subtle image differences.

Color Blending(#3113): This change resulted in speedups of up to 25%. It is ready to be merged.

OpenGL Rendering(#3154): This PR includes the whole code of the opengl rendering engine. Initially, I planned to code the engine’s base, but in the end, I implemented more tasks and researched/experimented with contour rendering. This PR is a concept and work in progress.

OpenGL Rendering

The goal was to implement just the base of the engine. But, since I gave this more time, I decided to work on some layers as well. I implemented the following tasks:-

  • ColorPixelMatrix
  • Blend
  • Blur(all types)
  • Pixel Gamma
  • Chroma Key
  • Luma Key

Now, it is easier to code new tasks for opengl. I spent the last few days of the coding period researching contour rendering. I read a few papers about approaches like Loop Blinn, Winding Number, Stencil then Cover, etc. Each approach had its advantages and disadvantages. Loop Blinn felt the right choice for the project, so I tried to implement it using the paper, but I faced many issues and decided that the project was too big for the time.

I tried NV_path_rendering, which is Nvidia’s extension to OpenGL for path rendering. I saw good results, but there were some differences, the biggest problem was that the time taken for rendering was huge. Because of the way this extension works, it is better to render many paths in 1 draw call. So, an optimizer that merges multiple contour layers can help decrease the rendering time if we use NV_path_rendering.

Random Findings

  • Giving fftw3 more threads results in speed gains for blur-heavy files.
  • Splitting the rendering into tiles helps in files with tasks that take a lot of time. But it is not simple, some layers like Blur can’t work correctly on split rendering. That is why each task needs to be split individually. My split PR attempts this only, it had a few problems, but they can be fixed.

Future Work

There is a lot that can be done to improve the OpenGL renderer.

  • More tasks can be implemented.
  • Better integration with the software renderer, resulting in a Hybrid Renderer. That makes intelligent choices for which renderer to use for rendering. For example, it is better to do blending with the software renderer if both layers are software layers, but in some cases, it will be better to use the OpenGL renderer. Since the OpenGL renderer works on only one thread, there is much opportunity for an intelligent hybrid renderer.
  • Opengl-based contour rendering can help, but it is a challenging project.

Acknowledgments

I extend my heartfelt thanks to my mentors for their invaluable guidance and patience during this GSoC journey. I’d also like to express my gratitude to the entire Synfig community for providing a welcoming and collaborative environment.

Special thanks to @ice0 and @rodolforg for their mentorship and encouragement.

Lastly, I appreciate Google for organizing the Google Summer of Code program, allowing students like me to contribute to open-source projects and gain real-world experience. This journey wouldn’t have been possible without your support and the vibrant Synfig community. I look forward to continued collaboration and growth within this open-source ecosystem.

8 Likes