revanced-integrations icon indicating copy to clipboard operation
revanced-integrations copied to clipboard

feat: remove usage of reflection in integrations

Open TheJeterLP opened this issue 3 years ago • 18 comments
trafficstars

🐞 Issue

Some patches (for example custom-playback-speed and default-video-quality use reflection inside the integrations. That should be changed as this decreases the user experience because reflection makes the youtube app slower.

❗ Solution

Remove the usage of reflection and move that logic to the actual Patch.

❓ Motivation

Follow the general unspoken rule of java development to not use reflection at all. Moving logic that currently uses reflection will move the time consuming logic from runtime to compile time which will increase the user experience.

TheJeterLP avatar Jul 22 '22 16:07 TheJeterLP

because reflection makes the youtube app significantly slower

I can not reproduce this.

oSumAtrIX avatar Jul 22 '22 16:07 oSumAtrIX

because reflection makes the youtube app significantly slower

I can not reproduce this.

Get an older phone and try again. You have a OnePlus 8 Pro, of course you cannot.

TheJeterLP avatar Jul 22 '22 16:07 TheJeterLP

Ask any actual java dev and they will tell you the same

TheJeterLP avatar Jul 22 '22 16:07 TheJeterLP

No need to ask anyone else, I just have to compare it on my device. I have also tried it on an old tablet where I can not reproduce it.

oSumAtrIX avatar Jul 22 '22 16:07 oSumAtrIX

No need to ask anyone else, I just have to compare it on my device. I have also tried it on an old tablet where I can not reproduce it.

How did you try it?

Also maybe its not that big of an effect right now. But when more reflection continues to be used, it will obv increase. Directly access fields and methods is always faster than accessing and calling them using reflection. Thats the point

TheJeterLP avatar Jul 22 '22 16:07 TheJeterLP

How did you try it? Also maybe its not that big of an effect right now

Yes & Yes.

oSumAtrIX avatar Jul 22 '22 16:07 oSumAtrIX

So general rule of any development is to make the code run the fastest way you can possibly do. Thats why the question about if reflection should be used or not is unneccessary. Theres only one answer for that.

TheJeterLP avatar Jul 22 '22 16:07 TheJeterLP

So the general rule of any development is to make the code run the fastest way you can possibly do

No, this is the wrong approach. Readability and understandable code are way better than a complicated approach, especially in such cases and where the difference is unnoticable as prevs said.

oSumAtrIX avatar Jul 22 '22 16:07 oSumAtrIX

So general rule of any development is to make the code run the fastest way you can possibly do.

Since we're able to achieve this goal and still be able to be failsafe using fingerprints, it should be changed to patches.

TheJeterLP avatar Jul 22 '22 16:07 TheJeterLP

So the general rule of any development is to make the code run the fastest way you can possibly do

No, this is the wrong approach. Readability and understandable code are way better than a complicated approach, especially in such cases and where the difference is unnoticable as prevs said.

changing the integrations to not use reflection does not make the code less readable or less understandable. Also, as previously said, it might no be recognizable for you for now. But if the use of reflection increases it will be. I've already read comments of people complaining that revanced is slower than vanced or stock youtube was.

TheJeterLP avatar Jul 22 '22 16:07 TheJeterLP

changing the integrations to not use reflection does not make the code less readable or less understandable

It very much does, due to now having to resort to an abstract approach where the patch has to embed the code - which was readable in the integrations - inside the app.

But if the use of reflection increases it will be.

It has to increase significantly. Reflective calls are being made thousands of times in a short time.

I've already read comments of people complaining that revanced is slower than vanced or stock youtube was.

Placebo as there is no significant difference yet.

oSumAtrIX avatar Jul 22 '22 16:07 oSumAtrIX

It very much does, due to now having to resort to an abstract approach where the patch has to embed the code - which was readable in the integrations - inside the app.

I don't see how that will decrease readability. App has to be decompiled to completely understand what the patches do anyways.

It has to increase significantly. Reflective calls are being made thousands of times in a short time.

Which is why it should be avoided to use for us. Especially using reflection to looping through all methods in a class.

Placebo as there is no significant difference yet.

Not for you, but you can't speak for the general user.

Also I thought that this discussion was over? You already agreed on changing the patches later.

TheJeterLP avatar Jul 22 '22 16:07 TheJeterLP

Also read this: https://ncrcoe.gitbooks.io/java-for-small-teams/content/specifics/1000_do_not_use_reflection.html

TheJeterLP avatar Jul 22 '22 16:07 TheJeterLP

I don't see how that will decrease readability.

As I said previously:

due to now having to resort to an abstract approach where the patch has to embed the code - which was readable in the integrations - inside the app.

Which is why it should be avoided to use for us.

Once again:

It has to increase significantly.

Hence it is not a high priority.

but you can't speak for the general user

I am the general user as I have tried what the general user has tried and was not possible to reproduce. Unless no reproducible steps or something like a recording is given you can not assume that it is not a placebo.

Also read this

No need to. I already said:

Readability and understandable code are way better than a complicated approach, especially in such cases and where the difference is unnoticable as prevs said.

Also:

Also I thought that this discussion was over?

Reason being because you continued it.

Why are you continuing to argue if you say the discussion is over?

oSumAtrIX avatar Jul 22 '22 16:07 oSumAtrIX

I did not continue it? You did by commenting this issue? You asked to create an issue which I did.

TheJeterLP avatar Jul 22 '22 16:07 TheJeterLP

https://github.com/revanced/revanced-integrations/issues/96#issuecomment-1192738420:

I can not reproduce this.

oSumAtrIX avatar Jul 22 '22 16:07 oSumAtrIX

#96 (comment):

I can not reproduce this.

Which started the discussion again.

TheJeterLP avatar Jul 22 '22 16:07 TheJeterLP

#96 (comment):

I can not reproduce this.

Which started the discussion again.

Please stop going off topic. The comment was related to this topic.

oSumAtrIX avatar Jul 22 '22 16:07 oSumAtrIX

I think that if you really need such a change to be made ASAP and the maintainers are currently not in favor of it, then you should fork the patch and maintain your own flavor of Revanced Integrations @TheJeterLP

The maintainers have made it so extensible, that anyone can take the project and extends or modify, I believe so, but I may be wrong

You will never force anyone to make a change by commenting here, even if you are right or wrong, this doesn't matter here. If you're perfectly sure that your change should make it upstream, then prove that your Revanced Integrations and your fork can out stand the official Revanced Integrations for older phone users, once you made that clear, maybe things will move upstream.

AkechiShiro avatar Sep 27 '22 17:09 AkechiShiro

I think that if you really need such a change to be made ASAP and the maintainers are currently not in favor of it, then you should fork the patch and maintain your own flavor of Revanced Integrations @TheJeterLP

The maintainers have made it so extensible, that anyone can take the project and extends or modify, I believe so, but I may be wrong

You will never force anyone to make a change by commenting here, even if you are right or wrong, this doesn't matter here. If you're perfectly sure that your change should make it upstream, then prove that your Revanced Integrations and your fork can out stand the official Revanced Integrations for older phone users, once you made that clear, maybe things will move upstream.

I was a team member when writing that issue and we discussed about it.

TheJeterLP avatar Sep 27 '22 18:09 TheJeterLP

Is this issue still relevant? It's now a year later, and custom-video-speed no longer uses reflections.

remember-video-quality use reflections only once when a new video first loads, and not anytime else.

The only other examples I can think of that still uses reflections is Sponsorblock. The seekbar drawing code of Sponsorblock (the set seekbar frame rectangle code) would be the biggest candidate, as it's called when the frame rectangle is updated (switching to/from full screen, or when closing/opening the app). I wondered how slow the reflections usage was for this one example, so I added some performance logging around the method, and to my surprise the runtime showed up as less than 100 nanosecond. That's less than 1/10th of one millionth of 1 second. If this ran in a loop this might be an issue, but the frame rect reflections call is a single call. So the performance cost of using reflections there is a meaningless amount of time.

The sponsorblock seek code also uses reflections, but that is called only when skipping segments, which is a maximum of maybe a dozen times for each videos (also a meaningless performance overhead).

Is there anywhere else reflections is still used? If there is nowhere else, then this issue can probably be closed.

LisoUseInAIKyrios avatar Jun 14 '23 21:06 LisoUseInAIKyrios

Reflection has nearly no impact on performance whatsoever, but it's not really good design here and should ideally never be used. Closing though until it opposes an actual problem ala https://en.m.wikipedia.org/wiki/Ostrich_algorithm

oSumAtrIX avatar Jun 15 '23 10:06 oSumAtrIX