fent / node-ytdl-core

YouTube video downloader in javascript.
MIT License
4.48k stars 790 forks source link

Please improve getBasicInfo's performance and ytdl's overall performance #997

Open richiedevs opened 3 years ago

richiedevs commented 3 years ago

Before creating an issue, please try the following

I've noticed that getInfo uses ~850ms on average, and getBasicInfo uses ~500ms, the code i've used to test this is:

const ytdl = require('ytdl-core');
const start = Date.now();
ytdl.getInfo('https://www.youtube.com/watch?v=HhjHYkPQ8F0').then(data => {
  return Date.now() - start;
})

and

const ytdl = require('ytdl-core');
const start = Date.now();
ytdl.getBasicInfo('https://www.youtube.com/watch?v=HhjHYkPQ8F0').then(data => {
  return Date.now() - start;
})

I believe and hope that the performance of ytdl's getBasicInfo could get further optimized, or add some array-like options to choose what kind of information i want to extract, and not get the entire gigantic object which is quite slow

richiedevs commented 3 years ago

I benchmarked this on my Ryzen 7 3700X @ 4.2 GHz processor using Wi-Fi 6 @ 600mbps

redbrain commented 3 years ago

Most of this time is waiting on requests from YouTube, afaik there's hardly anything that can be done to speed up the process. If you do find a timesave, please open a PR with it.

richiedevs commented 3 years ago

if that's the case, how is basicInfo faster than info?

richiedevs commented 3 years ago

Seems more like a processing-delay than request-delay

redbrain commented 3 years ago

if that's the case, how is basicInfo faster than info?

iirc getInfo() actually makes more requests, in order to download and decipher format/streaming information.

Seems more like a processing-delay than request-delay

I'll try to benchmark request time vs total processing time and have some more specific statistics on this.

gatecrasher777 commented 3 years ago

Using the innertube api with data compression is far more efficient. Especially, if you maintain a session, then each video info call is only a +-20kb zipped json transfer vs upwards of 3mb for watch page html, player js and json info page. For once-off download requests it wont make much difference. But if you are harvesting lots of video info for possible downloading/playing later, it makes a world of difference.

redbrain commented 3 years ago

if we can verify what you claim, using innertube could be a worthwhile time investment. I will look into it, and if any other maintainers could look into it that would be amazing

gatecrasher777 commented 3 years ago

@redbrain I think you can verify quite easily using https://github.com/gatecrasher777/ytcog, and you should be able to extract the structure of the innertube post requests from the code. I really think the innertube api is where all YouTube OS projects are heading, as more and more legacy resources fall by the wayside. Of course, YouTube isn't going to make it easy for us...

richiedevs commented 3 years ago

@gatecrasher777 nice project, will sure check it out!