Skip to content

Fix exponential behavior in accent production#834

Merged
k4b7 merged 1 commit intoKaTeX:masterfrom
sophiebits:noexp
Aug 30, 2017
Merged

Fix exponential behavior in accent production#834
k4b7 merged 1 commit intoKaTeX:masterfrom
sophiebits:noexp

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.

// 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.

@sophiebits sophiebits force-pushed the noexp branch 3 times, most recently from 3f05d53 to 4aa87b7 Compare August 30, 2017 05:05
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.

@k4b7
Copy link
Member

k4b7 commented Aug 30, 2017

@sophiebits thanks for finding this issue and fixing it.

@k4b7 k4b7 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