Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EXPERIMENTAL] Improve rendering time by rewriting STD140BufferFormat._write_padded() #4058

Merged

Conversation

chopan050
Copy link
Contributor

The original implementation of STD140BufferFormat._write_padded() used np.pad which is slow. In the given example scene, this method takes almost half of the rendering time.

This new implementation avoids that by creating a new array of zeroes instead. In this way, this method now takes 60x less time, and the total rendering time is almost halved.

Example scene:

class Twist(ThreeDScene):
    def construct(self):
        self.set_camera_orientation(theta=TAU/8, phi=TAU/5)

        def function(u, v):
            x = 8*u - 4
            y = 2*v - 1
            z = 1.0
            angle = TAU/4 * u
            point = (
                np.cos(angle) * np.array([x, y, z])
                + np.sin(angle) * np.array([x, -z, y])
            )
            return point
        
        surface = VGroup(Surface(function, resolution=(20, 5)))
        for i in range(3):
            face_copy = surface[0].copy()
            face_copy.rotate(TAU/4 * (i+1), RIGHT, ORIGIN)
            surface.add(face_copy)

        self.add(surface)

        self.begin_ambient_camera_rotation()
        self.wait(5)

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

@chopan050 chopan050 changed the base branch from main to experimental December 13, 2024 20:40
@JasonGrace2282 JasonGrace2282 merged commit 9f72377 into ManimCommunity:experimental Dec 13, 2024
2 of 4 checks passed
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