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)
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