Is there a hardcoded delay in `browser. tabs.duplicate(tabId)`?


(Juraj Masiar) #1

Hello,

I’ve noticed the browser.tabs.duplicate(tab.id) method takes about 400ms to complete, which is like 20 times more compare to browser.tabs.create(tab.url) which takes about 20ms.

Is there a reason for that? I know it’s not the same thing but it’s hard to believe there is a performance reason behind it related to copying tab history (even when there is none).
Try yourself:

const HighResolutionTimer = (name = '', startNow = false) => {
  let startTime, stopTime;
  if (startNow) start();
  return {
    start: start,
    stop: stop
  };
  function start() {
    startTime = performance.now();
  }
  function stop(message = '') {
    stopTime = performance.now();
    console.warn(`${name} ${message} time: ${stopTime - startTime}`);
  }
};
const tab = await browser.tabs.getCurrent();
const p = HighResolutionTimer('Speed test', true);
browser.tabs.duplicate(tab.id).then(() => p.stop('duplicate'));
browser.tabs.create({url: tab.url, active: true}).then(() => p.stop('create'));


(Baptiste Thémine) #2

This is because browser.tabs.duplicate() creates a new tab and copies all browsing history and session from the previous tab.


(Juraj Masiar) #3

Then the internal code must be really inefficient because it takes 400ms even with a fresh new tab that has no history or session.
In a programming world 400ms is forever. Something’s not right here.


(jscher2000) #4

How does it compare to interactive: right-click the tab > Duplicate Tab? With this tab, the new tab appears on the bar quickly, but there are a few seconds of (re)loading.


(Tomislav Jovanovic) #5

The delays you are seeing are likely from loading the page, which we shouldn’t be waiting for, and there’s bug 1394376 to change that, with a patch posted for review, so will probably be fixed soon.


(Juraj Masiar) #6

That does sounds very likely :slight_smile:
I will retested it once it’s merged in Nightly.
Thank you!

PS: link to the bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1394376