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

getFlatGraph: rewrite recursion to while loop #90

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

brightman9
Copy link

@brightman9 brightman9 commented Nov 30, 2019

To avoid call stack overflow when the graph has a large nesting depth. For example:

let illo = new Zdog.Illustration({
    element: '.canvas'
});

let parent = illo;
for (let depth = 0; depth < 1000; depth++) {

    let rotateX = new Zdog.Anchor({
        addTo: parent,
        rotate: { x: Zdog.TAU / 4 }
    });

    let rotateY = new Zdog.Anchor({
        addTo: rotateX,
        rotate: { y: Zdog.TAU / 6 }
    });

    let rotateZ = new Zdog.Anchor({
        addTo: rotateY,
        rotate: { z: Zdog.TAU / 8 }
    });

    parent = rotateZ;
}

illo.updateRenderGraph();

To avoid call stack overflow when the graph has a large nesting depth
@brightman9
Copy link
Author

brightman9 commented Nov 30, 2019

Other recursive functions also have the same problem(Anchor.prototype.update, Anchor.prototype.transform, Anchor.prototype.copyGraph and so on).
I think they could be rewritten to loop in a uniform way.

@desandro
Copy link
Member

Add a 👍 reaction to this issue if you would like to see this feature added. Do not add +1 comments — They will be deleted.

@desandro
Copy link
Member

Thank you for this contribution. I can see how this could be an improvement, but I see two issues

  1. There needs to be a separate fix so it works with Group
  2. As it is, I saw worse performance in some of my buggier demos, like Steam Spooky House

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants