Skip to content

Refactored reduce_across_dimension to get_extreme_coord_along_dimension#4656

Open
GoThrones wants to merge 4 commits intoManimCommunity:mainfrom
GoThrones:refactor-reduce-across-dimension
Open

Refactored reduce_across_dimension to get_extreme_coord_along_dimension#4656
GoThrones wants to merge 4 commits intoManimCommunity:mainfrom
GoThrones:refactor-reduce-across-dimension

Conversation

@GoThrones
Copy link
Copy Markdown
Contributor

Overview: What does this pull request change?

This PR improves the code of the erstwhile method reduce_across_dimension, and renames it to get_extreme_coord_along_dimenstion.

Motivation and Explanation: Why and how do your changes improve the library?

The erstwhile method's name: "reduce_across_dimension" was not intuitively named. This method is only called by one other method named length_over_dim() which is also in mobject.py file, in the entire source code of manimce, and the method's name was not intuitive enough as to what it did.

Reviewer Checklist

  • The PR title is descriptive enough for the changelog, and the PR is labeled correctly
  • If applicable: newly added non-private functions and classes have a docstring including a short summary and a PARAMETERS section
  • If applicable: newly added functions and classes are tested

@behackl
Copy link
Copy Markdown
Member

behackl commented Mar 26, 2026

Hi! IIRC length_over_dim is one of the most-called methods in a standard rendering flow. Did you benchmark in how far your changes affect performance / rendering time?

@GoThrones
Copy link
Copy Markdown
Contributor Author

GoThrones commented Mar 27, 2026

Here' the benchmarking code that i used:

from manim import *
import timeit

class BenchmarkScenePR(Scene):
    def construct(self):
        mob = Square()
        self.add(mob)

        results = timeit.repeat(
            lambda: mob.get_extreme_coord_along_dimension(np.max,0),
            number= 100000,
            repeat = 10
        )
        best = min(results[1:])
        print(f"100k calls: {best:.4f}s  ({best/100_000*1e6:.2f} µs/call)")


class BenchmarkScenemain(Scene):
    def construct(self):
        mob = Square()
        self.add(mob)

        results = timeit.repeat(
            lambda: mob.reduce_across_dimension(np.max,0),
            number=100000,
            repeat = 10
        )
        best = min(results[1:])
        print(f"100k calls: {best:.4f}s  ({best/100_000*1e6:.2f} µs/call)")
        
        

For main: time was 4.73 µs/call and for PR branch it was 4.68 µs/call.

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.

2 participants