Last active
April 18, 2018 16:56
-
-
Save fatso83/60106ac45e92c5590b01d82afe578343 to your computer and use it in GitHub Desktop.
Some debugging code for testing out a performance problem related to SVG defs on meny.no
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// the svg with id 'spinner' in the svg definitions causes a cpu | |
// load of approximately 24% constantly when monitored | |
// using Chrome Process Explorer (sorted on cpu usage), Shift-Esc | |
// some experiments on why this happens | |
const spinner = document.getElementById('spinner') | |
const defs = spinner.parentElement | |
const svg = defs.parentElement; | |
// to remove cpu use of approx 24%, just remove the element ... | |
const removeSpinner = () => defs.removeChild(spinner); | |
// to re-add the cpu spike: | |
const addSpinner = () => defs.appendChild(spinner) | |
// to adjust cpu usage from 24% to 12%, set the svg element to display:none | |
// things still work in Chrome, but this might cause bugs in other browsers | |
// as this removes the element from the DOM, thus potentially making it | |
// impossible to find when referencing it | |
const displayNone = () => svg.style.display = 'none'; | |
const displayInitial = () => svg.style.display = 'initial'; | |
console.log('finished setting up svg experiments') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment