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

Fix exponential behavior in accent production #834

Merged
merged 1 commit into from
Aug 30, 2017

Conversation

sophiebits
Copy link
Contributor

src/functions.js was returning two properties referring to the base; since buildHTML runs JSON.parse(JSON.stringify(tree)) to get an immutable copy, that meant we'd traverse and serialize and parse an exponentially-sized tree.

Test Plan: \breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{A}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}} renders instantly; previously, it reliably timed out with even half that depth.

@ronkok
Copy link
Collaborator

ronkok commented Aug 30, 2017

I like it.

@@ -453,7 +461,7 @@ const svgSpan = function(group, options) {
if (utils.contains(["widehat", "widetilde", "undertilde"], label)) {
// There are four SVG images available for each function.
// Choose a taller image when there are more characters.
const numChars = group.value.value.length;
const numChars = groupLength(group.value.base);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stretchy accents use body instead of base. Probably best to make them use the same thing. I have a slight preference for body because base makes me think of exponents, but either would be fine.

src/functions.js was returning two properties referring to the base; since buildHTML runs `JSON.parse(JSON.stringify(tree))` to get an immutable copy, that meant we'd traverse and serialize and parse an exponentially-sized tree.

Test Plan: `\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{\breve{A}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}` renders instantly; previously, it reliably timed out with even half that depth.
@sophiebits
Copy link
Contributor Author

sophiebits commented Aug 30, 2017

Opted for base since groupTypes.supsub has:

if (shouldHandleSupSub(group, options)) {
    return groupTypes[group.value.base.type](group, options);
}

which currently relies on op, accent, horizBrace all having .base. Should be good now though. Screenshots pass this time.

@kevinbarabash
Copy link
Member

@sophiebits thanks for finding this issue and fixing it.

@kevinbarabash kevinbarabash merged commit b27d701 into KaTeX:master Aug 30, 2017
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.

3 participants