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

Firefox performance improved with highlight feature #352

Merged
merged 11 commits into from
Dec 5, 2020
Merged

Firefox performance improved with highlight feature #352

merged 11 commits into from
Dec 5, 2020

Conversation

jwallet
Copy link
Contributor

@jwallet jwallet commented Apr 25, 2020

I got the same issue as the issues mentionned here, I did not added my build index.js at this time in Options - Collapsable files / Delete files. So highlighter was trying to colorize 6 minified lines:

  • x2 - 16,631 (these were actually taking 1sec each)
  • x2 ~281,000
  • x2 ~327,000

the last 4 were causing the script to crash, they resolved after 9secs each, but even then firefox was not responding, just scrolling up and down, I had to kill the tab after some minutes to kill Prism from keep trying to highlight the whole lines

firefox performance improvements

  • autocollapse: run it first and return if successful to kill the propagation because it won't be rendered anyway, just like delete does.
  • highligther: added promises when executing prism.highlightElement
  • highlighter: lines over the arbitrary max length of 9999 will be considered as minified and ignored
  • Prism: Updated prism form 1.15 to 1.20, I took the previous url from 1.15 to make sure I got the same addons and features from 1.15
  • Updated syntax second try logic (related to <add> <del> tags)

some tweak for diff selector

  • Now logs the element in console.error
  • new Set for selectors to make sure no duplicates are there
  • Valid if the element from the selector is aria-hidden or display:none

close #348
close #351
close #266

  • I updated the CHANGELOG.md
  • I tested the changes in this pull request myself
  • I added Automated Tests
  • I added an Option to enable / disable this feature
  • I updated the README.md, with pictures if necessary

@reyronald
Copy link
Member

I can't reproduce this bug in the dev branch 😕 . I tried creating a PR while having all extension's options enabled, and with both the new UI and old UI experience.

Can you think of what might be different in your environment versus mine? I'd like to be able to reproduce this locally to be able to properly review the PR

@jwallet
Copy link
Contributor Author

jwallet commented Apr 27, 2020

using firefox and old experience, looks like the element target can be reached if the pr is small, when is bigger, some elements gets removed (diff tab) by bitbucket when in the commit tab. this does happen when developping, firefox has some memory management issues when reloading, it cannot remove unused memory correctly, resulting in unmanaged memory. and the webpage gets slow and the error pops, at this time, firefox takes around 6gb ram space. so maybe an issue when the selector is triggered at the same time it gets removed by the DOM. Slow computers might have the same issue.

I can't reproduce this bug as well, this morning, but I remember it was coming from <section> blocks. I will try to find the proper path to test it

- valid autocollapse first and return if successful to kill the propagation
- added promises to prism highlight
- lines over the arbitrary max length of 9999 will be considered as minified
'#pr-tab-content',
'#commit',
'#diff',
]
const diffSelector = 'section.bb-udiff'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

added back the previous selector but kept validation hidden/visible line 197:202

@jwallet jwallet changed the title updated main.js error while creating pr, dom not found Firefox performance improved with highlight feature May 14, 2020
@@ -39,10 +39,10 @@ export default function syntaxHighlight(diff, afterWordDiff) {
}

const $diff = $(diff)
syntaxHighlightSourceCodeLines($diff)
syntaxHighlightSourceCodeLines($diff, 'pre.source:not([class*=language])')

Copy link
Contributor Author

Choose a reason for hiding this comment

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

first time we highlight we never have class language


afterWordDiff(() => {
syntaxHighlightSourceCodeLines($diff)
syntaxHighlightSourceCodeLines($diff, '.addition pre, .deletion pre')
Copy link
Contributor Author

@jwallet jwallet May 14, 2020

Choose a reason for hiding this comment

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

second time, we will want to look for tags pre:has(ins) pre:has(del) but the word-diff block only have <ins> elements in the addition block, the deletion block will be re-rendered as well, so we have to re-highlight there too. so the selector is .addition pre, .deletion pre and anyway the mutation-observer will not ask to re-render a diff block that as no word-diff ins/del

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

return
}

Prism.highlightElement(preElement)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe we can use web worker, but Prism warn about using async highlight... web workers are slower and just limiting the text to a max length of 9999 is quite enough. Sure it will skip this line, but the ui does not freezes anymore

Prims.highlightElement(element, true, () => {}); // async with web worker

Copy link
Member

@reyronald reyronald left a comment

Choose a reason for hiding this comment

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

Looks good to me!

I'll be merging this by Monday, would like to wait to see if you can answer the question I left before then.

Thanks a lot for working on this as usual 🙏

const { classList, firstChild, innerText } = preElement

if (firstChild.$$rbb_isSyntaxHighlighted) {
reject(new Error('Already highlighted'))
Copy link
Member

Choose a reason for hiding this comment

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

Do we have to reject with an Error here? Can't we just ignore this line, resolve, and skip to the next promise? Worried that we will polluting the console and stack with unhandled exceptions that are unactionable and don't really represent an error conceptually

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no no need to add an error. you can just reject. sorry I lately left github for other stuff I do not think I will give more time to projects outside of those I am maintening.

Copy link
Member

Choose a reason for hiding this comment

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

No problem @jwallet ! Thanks a lot for all you've contributed so far! Greatly appreciated ♥

@reyronald reyronald merged commit 9ea8d1b into refined-bitbucket:dev Dec 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants