Skip to content

Instantly share code, notes, and snippets.

@fatso83
Last active April 18, 2018 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fatso83/60106ac45e92c5590b01d82afe578343 to your computer and use it in GitHub Desktop.
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
// 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