[GSOC 2023] Performance Optimization

I will use this thread to report my progress every week.

2 Likes

Weekly Report: 29 May - 4 June

  • How was the last week? What did you accomplish?

    • Understood most of the rendering code.
    • Wrote pages for Synfig docs(#104), explaining Targets, Surfaces, Tasks, Render Engine, Render Queue, and Optimizers.
    • Experimented with Splitting rendering into tiles.
  • What is the #1 thing slowing you down?

    • I have not completely understood TaskSurface and its use. So the documentation for it is still TODO.
  • What do you want to have done by the end of next week?

    • I want to work on Splitting optimization. I have two ideas that I will discuss with the mentors and go forward from there. My goal for the week is to decide which optimization to do and try to implement it by the end of the week.
3 Likes

Hi,

First of all, nice to see you are working on this subject, thanks!

I would like to comment you that apart from trying to boost overall Synfig processes, under macOS there is an special slowdown, actually, IMHO it’s usable but so sluggish (even choppy…). If you could have a look at it we would love it as macOS performance is, as I told you, so close to unusable…

And, indeed, if you need a macOS tester here I am :wink:

Thanks again!

Hi,
Thank you for your message and your interest in my work on the subject. I appreciate your feedback regarding the performance of Synfig on macOS. While I would love to investigate and address the slowdown you mentioned, I don’t currently have access to a macOS environment for running the necessary benchmarks to identify the issue.

I apologize for any inconvenience this may cause, but my GSOC project focuses on specific tasks that don’t involve macOS. However, if I manage to finish my assigned tasks earlier, I will certainly try to allocate some time to investigate the macOS performance concerns you raised.

Is there any thread for this issue?

Thank you again for your understanding.

1 Like

Did you check that it was not an issue of GTK with HiDpi? It seems common.

Pandagrapher commented on May 18, 2020 •

Hello All,

I have observed the same UI latency on my new MacBook Pro 16" with official 5.8 release. Making some researches, I discovered that other program that uses GTK3 have the same issue (Inkscapes for its freshly new 1.0 version, for instance) :
Inkscape 1.0 Release Candidate | Hacker News
chat.inkscape.org
WIP: gdkwindow reuse cairo_surface_t for performance gain (GTK 3.24) (!1441) · Merge requests · GNOME / gtk · GitLab

The problem seems to be clearly a GTK bug with HiDPI on MacOS. If you change your screen scaling (what I tested) to the lower resolution (Preferences → Monitor → Choose “Bigger Text”) or use a non HiDPI screen, UI lag disappear.

Maybe the new GTK version will solve the issue !
Pierre

Weekly Report: 5 June - 11 June

  • How was the last week? What did you accomplish?

    • Tested different ways of spliting rendering into tiles. Removing pixel rendering limit and enabling split rendering reduced render time differently for files. In some cases it reduced upto 10 secs. Imagemagick reports difference in output files but it is not visible. It also crashed sometimes.
    • Experimented with Surface::blit_to and color blend functions.
  • What is the #1 thing slowing you down?

  • What do you want to have done by the end of next week?

    • My task for the next two weeks is related to color blending functions. I will try to optimize different blend functions and the places they are used.
    • I will also try to find the cause of crash when using split optimization.
5 Likes

I’ll open an issue in Github as I have done some tests and they didn’t work… I guess there is the place to discuss it, here it is

Thanks for your help

1 Like

We should evaluate what these differences are and if they are improving or degrading the rendered image.

Ugh. What about make some small test codes? Like unit or feature tests. Add them in synfig-core/test :slight_smile:

Also, try to share your code so we maybe can help you/us :wink:

1 Like

Hey, I will be making a few PRs soon. Last week due to traveling to college I couldnt work a lot.

1 Like

Weekly Report: 12 June - 18 June

  • How was the last week? What did you accomplish?
    • Tested using multiple threads in fftw3. Resulted in speed gain in a blur heavy file, but the case is specific to files using big blurs.
    • Debugged split optimizer. Created a PR#3112
    • Refactor color blending function, resulting in a small speed gain. PR#3113
  • What is the #1 thing slowing you down?
    • Due to traveling to college, I couldn’t get much done last week
  • What do you want to have done by the end of next week?
    • I want to discuss it with the mentors and decide.
    • Proper fix pixel processor crash in Split Optimizer.
1 Like

I’m just wondering if rendering beyond the canvas region can be done in the viewport.

3 Likes

Weekly Report: 19 June - 25 June

  • How was the last week? What did you accomplish?
    • Discussed architecture of opengl renderer with the mentors and started programming it.
    • Wrote code for shader loading and context creation.
  • What is the #1 thing slowing you down?
    • I am trying to understand ColorMatrix so I can implement its opengl task.
  • What do you want to have done by the end of next week?
    • Opengl Surface
    • Blend Task
1 Like

Weekly Report: 26 June - 2 July

  • How was the last week? What did you accomplish?
    • Wrote code for framebuffers
    • Implemented surface_gl
    • Started working on ColorPixel matrix task implementation in opengl.
  • What is the #1 thing slowing you down?
    • I am currently debugging an issue with ColorPixel matrix task.
    • I am having some trouble understanding target rect in subtasks. I will discuss it with mentors.
  • What do you want to have done by the end of next week?
    • Complete color pixel matrix task.
    • Start on blend task.
2 Likes

Weekly Report: 3 July - 10 July

  • How was the last week? What did you accomplish?
    • Finish Color Pixel Matrix task
    • Implement gl blend tasks
  • What is the #1 thing slowing you down?
    • Some blend functions like hue and behind are not working properly. I am currently debugging them.
  • What do you want to have done by the end of next week?
    • Working blend task for all blend functions.
4 Likes

(Not so)Weekly Report: 11 July - 29 July

  • How was the last few days? What did you accomplish?
    • Fix all blend functions.
  • What is the #1 thing slowing you down?
    • My linux broke around mid eval, which took me couple of days to fix.
  • What do you want to have done by the end of next week?
    • Work on blur gl task.
2 Likes

Weekly Report: 30 July - 4 August

  • How was the last few days? What did you accomplish?
    • Implement all blur types in opengl renderer.
  • What is the #1 thing slowing you down?
  • What do you want to have done by the end of next week?
    • Write more test files for checking differences in output between software and opengl blurring.
5 Likes

Weekly Report: 5 August - 11 August

  • How was the last few days? What did you accomplish?
    • Fix some issues with blurring.
    • Work on Affine Transformation opengl task. But I am skipping it for now, since its not used much.
    • Implement Pixel Gamma task, which is used by layers like color correct.
    • Implement chroma key opengl task, but not usable right now because of build issues. Fixing which requires architectural changes to the opengl renderer.
  • What is the #1 thing slowing you down?
  • What do you want to have done by the end of next week?
    • Clean up architecture of the opengl renderer, so that modules can use it easily.
    • Fix chroma key opengl task.
4 Likes

Weekly Report: 12 August - 18 August

  • How was the last few days? What did you accomplish?
    • Some minor changes to help writing GL tasks for modules. I thought major changes might be required but nothing major was needed.
    • Implement chroma key and luma key task.
    • Started with the contour task, I read the software implementation and I am currently reading a paper for contour rendering. It requires me to read up on a few more things, but I believe that if I can get this working then it will be really beneficial.
  • What is the #1 thing slowing you down?
  • What do you want to have done by the end of next week?
    • Read about different approaches used for GPU based path rendering. Figure out if any is helpful in synfig scene i.e. static curves.
3 Likes

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