community icon indicating copy to clipboard operation
community copied to clipboard

Optimize Rectangle class memory management and performance, file: vertex_instructions.pyx (part of the issue #8664) [WIP]

Open tuliogv opened this issue 1 year ago • 6 comments

This commit overhauls the Rectangle class by implementing direct memory management in C. Changes include:

  • Direct allocation and deallocation of vertex memory using malloc and free, respectively, to minimize Python's overhead.
  • Update vertices directly using pointer arithmetic, enhancing the update operations efficiency.
  • Integrated these changes into the property setters for and , ensuring immediate updates on vertex data without intermediary Python object manipulation.

These improvements lead to a more efficient use of memory and a performance increase of approximately 5% in rendering operations, which is particularly beneficial for applications requiring dynamic graphic updates.

Maintainer merge checklist

  • [ ] Title is descriptive/clear for inclusion in release notes.
  • [ ] Applied a Component: xxx label.
  • [ ] Applied the api-deprecation or api-break label.
  • [ ] Applied the release-highlight label to be highlighted in release notes.
  • [ ] Added to the milestone version it was merged into.
  • [ ] Unittests are included in PR.
  • [ ] Properly documented, including versionadded, versionchanged as needed.

tuliogv avatar May 13 '24 02:05 tuliogv

Thanks for opening your first pull request here! 💖 Please check out our contributing guidelines.

welcome[bot] avatar May 13 '24 02:05 welcome[bot]

I tested results runining 100 instances of 10000 rectangues creations several times, and it gets an average of 5% improvements.

before: testeOrig

after: TesteMod

tuliogv avatar May 13 '24 02:05 tuliogv

Hi @tuliogv,

From a first glance seems something is missing there. Is some commit missing, or you're still working on it? (If it's the latter one, please mark it as WIP via [WIP] in PR name)

misl6 avatar May 22 '24 18:05 misl6

Thank you for checking on the pull request. I am indeed still working on it, specifically on refactoring the classes. My intention is not to rush through this process as others might also be working on related issues. To coordinate our efforts effectively, I've suggested that we mark the classes each one of us is refactoring. This way, we can test each one thoroughly. Once all the classes are refactored, we could proceed with a general merge. However, if there are no other contributors currently working on this, I can complete the refactoring of all the classes and update the PR accordingly. Please let me know how you would like to proceed!

Best regards, Tulio

tuliogv avatar May 22 '24 18:05 tuliogv

As per today, no contributors are working on vertex instructions refactoring.

So, feel free to make all the appropriate changes (but remind to add [WIP] in the PR title, and remove it when is ready for a review)

misl6 avatar May 22 '24 19:05 misl6

I'm still working on the changes and i'm also trying to test every thing properly, this is going to take a while...

tuliogv avatar May 27 '24 01:05 tuliogv