prettier: Severe performance degradation on small code. 5+ minutes to format

Environments:

  • Prettier Version: 1.13.7
  • Running Prettier via:
  • Runtime: Node 10
  • Operating System: Windows

Steps to reproduce:

const prettier = require('prettier')
var code = 'var render = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _vm._m(0)}\n' +
  'var staticRenderFns = [function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c(\'header\',{staticClass:"m-grid__item m-header ",attrs:{"id":"m_header","m-minimize":"minimize","m-minimize-mobile":"minimize","m-minimize-offset":"10","m-minimize-mobile-offset":"10"}},[_c(\'div\',{staticClass:"m-header__top"},[_c(\'div\',{staticClass:"m-container m-container--fluid m-container--full-height m-page__container"},[_c(\'div\',{staticClass:"m-stack m-stack--ver m-stack--desktop"},[_c(\'div\',{staticClass:"m-stack__item m-stack__item--right m-header-head",attrs:{"id":"m_header_nav"}},[_c(\'div\',{staticClass:"m-topbar  m-stack m-stack--ver m-stack--general",attrs:{"id":"m_header_topbar"}},[_c(\'div\',{staticClass:"m-stack__item m-topbar__nav-wrapper"},[_c(\'ul\',{staticClass:"m-topbar__nav m-nav m-nav--inline"},[_c(\'li\',{staticClass:"m-nav__item m-nav__item--accent m-dropdown m-dropdown--large m-dropdown--arrow m-dropdown--align-center \\tm-dropdown--mobile-full-width",attrs:{"m-dropdown-toggle":"click","m-dropdown-persistent":"1"}},[_c(\'div\',{staticClass:"m-dropdown__wrapper"},[_c(\'div\',{staticClass:"m-dropdown__inner"},[_c(\'div\',{staticClass:"m-dropdown__body"},[_c(\'div\',{staticClass:"m-dropdown__content"},[_c(\'div\',{staticClass:"tab-content"},[_c(\'div\',{staticClass:"tab-pane",attrs:{"id":"topbar_notifications_events","role":"tabpanel"}},[_c(\'div\',{staticClass:"m-scrollable",attrs:{"data-scrollable":"true","data-height":"250","data-mobile-height":"200"}},[_c(\'div\',{staticClass:"m-list-timeline m-list-timeline--skin-light"},[_c(\'div\',{staticClass:"m-list-timeline__items"},[_c(\'div\',{staticClass:"m-list-timeline__item"},[_c(\'span\',{staticClass:"m-list-timeline__badge m-list-timeline__badge--state1-success"}),_c(\'a\',{staticClass:"m-list-timeline__text",attrs:{"href":""}},[_vm._v("New order received")]),_c(\'span\',{staticClass:"m-list-timeline__time"},[_vm._v("Just now")])]),_c(\'div\',{staticClass:"m-list-timeline__item"},[_c(\'span\',{staticClass:"m-list-timeline__badge m-list-timeline__badge--state1-danger"}),_c(\'a\',{staticClass:"m-list-timeline__text",attrs:{"href":""}},[_vm._v("New invoice received")]),_c(\'span\',{staticClass:"m-list-timeline__time"},[_vm._v("20 mins")])]),_c(\'div\',{staticClass:"m-list-timeline__item"},[_c(\'span\',{staticClass:"m-list-timeline__badge m-list-timeline__badge--state1-success"}),_c(\'a\',{staticClass:"m-list-timeline__text",attrs:{"href":""}},[_vm._v("Production server up")]),_c(\'span\',{staticClass:"m-list-timeline__time"},[_vm._v("5 hrs")])]),_c(\'div\',{staticClass:"m-list-timeline__item"},[_c(\'span\',{staticClass:"m-list-timeline__badge m-list-timeline__badge--state1-info"}),_c(\'a\',{staticClass:"m-list-timeline__text",attrs:{"href":""}},[_vm._v("New order received")]),_c(\'span\',{staticClass:"m-list-timeline__time"},[_vm._v("7 hrs")])]),_c(\'div\',{staticClass:"m-list-timeline__item"},[_c(\'span\',{staticClass:"m-list-timeline__badge m-list-timeline__badge--state1-info"}),_c(\'a\',{staticClass:"m-list-timeline__text",attrs:{"href":""}},[_vm._v("System shutdown")]),_c(\'span\',{staticClass:"m-list-timeline__time"},[_vm._v("11 mins")])]),_c(\'div\',{staticClass:"m-list-timeline__item"},[_c(\'span\',{staticClass:"m-list-timeline__badge m-list-timeline__badge--state1-info"}),_c(\'a\',{staticClass:"m-list-timeline__text",attrs:{"href":""}},[_vm._v("Production server down")]),_c(\'span\',{staticClass:"m-list-timeline__time"},[_vm._v("3 hrs")])])])])])])])])])])])])])])])])])])])])}]\n' +
  'render._withStripped = true'
console.log('START')

var fcode = prettier.format(code, { semi: false, parser: 'babylon' });
console.log('HURRAY')

I digged a bit into code and found that function printGenerically called 570+ times and each time its slower and slower, on 566 time it take 1 second till next call. On 570 time - 7 seconds. On 571 - 15seconds. 572 - 30 seconds. And it increases exponentially.

That code in var is produced by vue template compiler, and the consequence of this slowness of prettier lead to 5+ compile time of corresponding simple vue template in dev mode ( where compiler use prettier to format output)

Expected behavior:

take second?

Actual behavior: take 5+ minutes

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 25
  • Comments: 20 (4 by maintainers)

Most upvoted comments

Yep, the code that i pasted in issue is just a cut from real code. On full real code it wasnt able to finish in 30minute time, didnt waited longer. I would say its not even performance issue at that stage, more like a breaking bug because it make unusable.

Any updates?

same issue …

Is there any plans to resolve this…?

Same here…

Another one from #6227

var render = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('layout-manager',[_c('p',[_vm._v("Hello!")]),_vm._v(" "),_c('p',{staticClass:"katex-block"},[_c('span',{staticClass:"katex-display"},[_c('span',{staticClass:"katex"},[_c('span',{staticClass:"katex-mathml"},[_c('math',[_c('semantics',[_c('mrow',[_c('mfrac',[_c('mrow',[_c('msub',[_c('mi',[_vm._v("A")]),_c('mn',[_vm._v("1")])],1),_c('msub',[_c('mi',[_vm._v("B")]),_c('mn',[_vm._v("2")])],1)],1),_c('mi',[_vm._v("C")])],1)],1),_c('annotation',{attrs:{"encoding":"application/x-tex"}},[_vm._v("\\frac{A_1B_2}{C}")])],1)],1)],1),_c('span',{staticClass:"katex-html",attrs:{"aria-hidden":"true"}},[_c('span',{staticClass:"base"},[_c('span',{staticClass:"strut",staticStyle:{"height":"2.04633em","vertical-align":"-0.686em"}}),_c('span',{staticClass:"mord"},[_c('span',{staticClass:"mopen nulldelimiter"}),_c('span',{staticClass:"mfrac"},[_c('span',{staticClass:"vlist-t vlist-t2"},[_c('span',{staticClass:"vlist-r"},[_c('span',{staticClass:"vlist",staticStyle:{"height":"1.36033em"}},[_c('span',{staticStyle:{"top":"-2.314em"}},[_c('span',{staticClass:"pstrut",staticStyle:{"height":"3em"}}),_c('span',{staticClass:"mord"},[_c('span',{staticClass:"mord mathdefault",staticStyle:{"margin-right":"0.07153em"}},[_vm._v("C")])])]),_c('span',{staticStyle:{"top":"-3.23em"}},[_c('span',{staticClass:"pstrut",staticStyle:{"height":"3em"}}),_c('span',{staticClass:"frac-line",staticStyle:{"border-bottom-width":"0.04em"}})]),_c('span',{staticStyle:{"top":"-3.677em"}},[_c('span',{staticClass:"pstrut",staticStyle:{"height":"3em"}}),_c('span',{staticClass:"mord"},[_c('span',{staticClass:"mord"},[_c('span',{staticClass:"mord mathdefault"},[_vm._v("A")]),_c('span',{staticClass:"msupsub"},[_c('span',{staticClass:"vlist-t vlist-t2"},[_c('span',{staticClass:"vlist-r"},[_c('span',{staticClass:"vlist",staticStyle:{"height":"0.30110799999999993em"}},[_c('span',{staticStyle:{"top":"-2.5500000000000003em","margin-left":"0em","margin-right":"0.05em"}},[_c('span',{staticClass:"pstrut",staticStyle:{"height":"2.7em"}}),_c('span',{staticClass:"sizing reset-size6 size3 mtight"},[_c('span',{staticClass:"mord mtight"},[_vm._v("1")])])])]),_c('span',{staticClass:"vlist-s"},[_vm._v("​")])]),_c('span',{staticClass:"vlist-r"},[_c('span',{staticClass:"vlist",staticStyle:{"height":"0.15em"}},[_c('span')])])])])]),_c('span',{staticClass:"mord"},[_c('span',{staticClass:"mord mathdefault",staticStyle:{"margin-right":"0.05017em"}},[_vm._v("B")]),_c('span',{staticClass:"msupsub"},[_c('span',{staticClass:"vlist-t vlist-t2"},[_c('span',{staticClass:"vlist-r"},[_c('span',{staticClass:"vlist",staticStyle:{"height":"0.30110799999999993em"}},[_c('span',{staticStyle:{"top":"-2.5500000000000003em","margin-left":"-0.05017em","margin-right":"0.05em"}},[_c('span',{staticClass:"pstrut",staticStyle:{"height":"2.7em"}}),_c('span',{staticClass:"sizing reset-size6 size3 mtight"},[_c('span',{staticClass:"mord mtight"},[_vm._v("2")])])])]),_c('span',{staticClass:"vlist-s"},[_vm._v("​")])]),_c('span',{staticClass:"vlist-r"},[_c('span',{staticClass:"vlist",staticStyle:{"height":"0.15em"}},[_c('span')])])])])])])])]),_c('span',{staticClass:"vlist-s"},[_vm._v("​")])]),_c('span',{staticClass:"vlist-r"},[_c('span',{staticClass:"vlist",staticStyle:{"height":"0.686em"}},[_c('span')])])])]),_c('span',{staticClass:"mclose nulldelimiter"})])])])])])])])}
var staticRenderFns = []
render._withStripped = true