Wolvan / Homebr3w

A Homebrew browser for 3ds
MIT License
50 stars 8 forks source link

How to get a major performance improvement #13

Closed ksanislo closed 8 years ago

ksanislo commented 8 years ago

I finally had a chance to look into Keep-Alive on the 3DS... It seems to be on by default, though I've made a merge to ctrulib to make this a selectable option.

You can take advantage of this by adding an additional header to requests for the API and when collecting any images, and it doesn't seem to hurt to have it on for everything.

Set it like this (it can go before or after the User-Agent header, placement is up to you):

Network.downloadFile(downloadURL, path, "Connection: keep-alive\nUser-Agent: Homebr3w/"..APP_VERSION, method, jsondata)

This will instruct the 3DS to maintain the HTTP socket for up to 5 seconds, in case there is another request to the same server, so there's a HUGE speed improvement for repeated requests. Try wiping your image cache and comparing the speed with and without the Keep-Alive header set for a great example of this.

Wolvan commented 8 years ago

I.. I am in absolute awe, the speed improvement is amazing. Thanks for giving me a heads up about this!

ksanislo commented 8 years ago

I was pretty surprised the 3DS seems to have the feature enabled by default, probably since fw 2.0.0 when the enable/disable flag was introduced. All it needed was the header to tell the remote server that we can handle it. Of course, like nearly everything else pertaining to HTTP on the system, no one had ever actually looked into it or how to use it correctly. ;)

Wolvan commented 8 years ago

I don't know about the current progress of the 3ds scene, but is HTTP something that's like, barely known?

ksanislo commented 8 years ago

Smea and/or yellows8 figured it out just enough of the http:c syscalls to download the NinjaHax ROP bin and produced the really terrible non-ssl example in 3ds-examples that everyone bases their code on (including the broken Lua stuff). Pretty much all the HTTP improvements that have come out since January or so to handle using the 3ds on the web have been done by myself, with the exception of ssl:c sockets, which I suspect was done since https:// wasn't supported in http:c at the time.

Wolvan commented 8 years ago

You are doing god's work here, mister. Thanks for doing this for the community.

ksanislo commented 8 years ago

lol... Thanks. As I've said before, I'm just really tired of pulling out my SD cards. The damned thing has an internet connection, it should be able to properly utilize that so I never have to remove the SD to load up new stuff again. ;)

ksanislo commented 8 years ago

Also... SERIOUS kudos for this app... It makes installing things so freakin' simple now.

Wolvan commented 8 years ago

Thanks! Doing my best to satisfy. The only other thing the app might need is being able to download extra files an app might need, but it's nice the way it is right now already.

Give yourself some credit though, this probably wouldn't have been possible without your help at all.

Anyways, the only other thing I'd hope for is people using it. You have analytics, don't you? Are you getting lots of requests from Homebr3w?

I guess I shall just hope and continue to dream of Homebr3w being featured somewhere important. Plailect's guide maybe, hehe

ksanislo commented 8 years ago

I'll try to get some hard numbers when I'm back from lunch, but there's got to be at least a few hundred active users. We average maybe 400 individual applications installed via homebr3w each day.

ksanislo commented 8 years ago

114 distinct IP addresses have accessed POST on /v0/ since 5AM with a Homebr3w User-Agent header, it's probably safe to say those are all independent users. It's a bit harder to tell them apart after each day... We could probably generate some kind of random UUID or other tracking method to be passed in the request from your app, to identify a specific device if you want more accurate numbers.

Wolvan commented 8 years ago

114 distinct IPs, that's pretty cool I think! Analytics might be interesting, but I am not sure how the users would like that. I'll open an issue for that specifically where we can talk about that further. See #14