-
Notifications
You must be signed in to change notification settings - Fork 864
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The performance of version 1.7.14 has gone backwards #1365
Comments
Oh well, I found out that 1.7.13 works the same as 1.7.12, but it doesn't work as well since 1.7.14-RC1,all the code in the project has not changed, I just replaced the Rhino-runtime dependency, like this
Does anyone have a similar problem? Does the author have any good suggestions? @p-bakker |
If you're running it on Android, do you have the |
Any chance to share the whole code of the calc() function to give us a chance to profile? |
Yes,I have set it like this: Context jsContext = new RhinoAndroidHelper(ContextHolder.getContext()).enterContext();
// Context jsContext = Context.enter();
jsContext.setOptimizationLevel(-1);
jsContext.setLanguageVersion(Context.VERSION_ES6);
jsContext.setLocale(Locale.getDefault());
jsContext.setWrapFactory(new WrapFactory());
ImporterTopLevel scope = new ImporterTopLevel();
scope.initStandardObjects(Context.getCurrentContext(), false); |
No problem, but this calc method is very complicated internally, this method is used to calculate astronomical related data |
This js file is very large, and the internal calculation is very complicated, maybe we only need a complex calculation to simulate it |
I tried to run your $ java -jar buildGradle/libs/rhino-1.7.14.jar -version 200 -opt -1 xingdu.js
time--> 95
$ java -jar buildGradle/libs/rhino-1.7.13.jar -version 200 -opt -1 xingdu.js
time--> 92
$ java -jar buildGradle/libs/rhino-1.7.12.jar -version 200 -opt -1 xingdu.js
time--> 94 These values is just an example. In 1.7.14 it went from about 100 to 120, and in 1.7.12 and 1.7.13 it went from about 90 to 100. Perhaps it is different in the Android environment. |
Well, thank you very much, but, in my opinion, PC devices are more powerful than mobile phones, so the difference is not obvious. Here are some of my guesses:
|
I recall having to add some synchronization around a global DateFormat object, since DateFormat is not actually thread-safe. It'd be interesting to look at the NativeDate class and see if any of that synchronization is contributing to bad performance, and if we could address it by not trying to have a global object. |
Well, these days, I add time-consuming statistics before and after each line of code in getXingdu,and i seem to have found something. Most of the time is spent on this method, but in the v1.7.13 version, it will be very fast after multiple calls. Does anyone know why? @tuchida @gbrail @rbri |
@SevenNight2012 The |
Ok, this file is really big, here is the gist address |
Thanks. Can the code for this comment be deleted? #1365 (comment) |
I need to explain the general function of this file, which is to calculate the position of the sun, moon and other stars on the earth's ecliptic according to time~ |
Okay,please wait~ |
Look at it now!I've dealt with that comment |
The only cause I can think of so far is the implementation of BigInt (ref. #837). However, when I implemented this, I measured micro-benchmarks and even a small change in the code changed the results significantly. Quantitative measurement is difficult because of the possible influence of the optimization mechanism of the JVM. |
Thank you very much, I think the BigInt you mentioned is indeed possible, because in fact, I also found that the doArithmetic method of the Interpreter class is obviously time-consuming in version 1.7.14, but this does not seem to be the root cause |
I disassembled Interpreter.class in 1.7.13 and 1.7.14 jar files. $ javap -v -p ./Interpreter.class > ./Interpreter.dump rhino/src/org/mozilla/javascript/Interpreter.java Line 1207 in 4c95547
The switch statements changed in the commit you found were both
I am not very familiar with JVM. Based on that I have measured that In Dalvik, |
@SevenNight2012 the commit you referred to adds support for template literals. Before the commit any strings delimited by backticks (`) were processed as non-template, regular strings. So if you're code uses backtick-delimited strings, as of the referred commit those strings will now be processed as template strings, thus requiring more processing, thus causing a difference in performance. Nothing else in the commit stand out to me as a potential cause of performance degradation when NOT using backtick-delimited strings (but I could be wrong) |
Well, I built a lot of jars to find the problem, maybe there is really something in this commit~ |
Can you help us understand how you're measuring the performance of this?
I built a little tool that uses JMH to run a script (or call a function)
and combined with "git bisect" that tool makes it pretty easy to detect a
performance regression. (I'll try to publish it soon.) However, I ran your
script with this tool on 1.7.13 and 1.7.14 and the current master branch
and performance was essentially the same. This is on a Linux box in both
interpreted and compiled mode.
So, is there a particular function (and parameters) that we can call using
your script so that we can test for ourselves?
…On Sat, Aug 19, 2023 at 8:41 AM 徐星晨 ***@***.***> wrote:
@SevenNight2012 <https://github.com/SevenNight2012> the commit you
referred to adds support for template literals.
Before the commit any strings delimited by backticks (`) were processed as
non-template, regular strings.
So if you're code uses backtick-delimited strings, as of the referred
commit those strings will now be processed as template strings, thus
requiring more processing, thus causing a difference in performance.
Nothing else in the commit stand out to me as a potential cause of
performance degradation when NOT using backtick-delimited strings (but I
could be wrong)
[image: image]
<https://user-images.githubusercontent.com/10094410/261806231-e4892c64-9d70-411d-8bbc-4483a85b5b3b.png>
Well, I built a lot of jars to find the problem, maybe there is really
something in this commit~
I'll try to look at that commit, but I don't know much about rhino
internals, would you like to take a look together?
—
Reply to this email directly, view it on GitHub
<#1365 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAD7I27BZHPTV7B27VPQKH3XWDNEHANCNFSM6AAAAAA3H7YHFA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Well, actually, I'm running rhino on an Android device, and I'm measuring its performance based on how time-consuming the methods are. This may not be comprehensive, but it should be intuitive. I'll show you an Android demo later. |
Hi, I uploaded my local rhino demo to my github, you can take a look, this is an Android demo, maybe you need to download AndroidStudio |
This is because the JIT compilation of the interpretLoop method fails, resulting in performance degradation.
|
Wow,thank you very much~ |
@gbrail @p-bakker Secondly,i try to imitate what RegExp does,below is my code In addition,what I did above is only to enable rhino to execute JIT on the Android platform. I am not sure whether it can also improve performance on other platforms. Lastly,as we can see in the second image, compiler allocated 7392KB to compile the interpretLoop method. |
Sry for not responding to your findings sooner Have a bit of a hard time what your findings are. Is this summary correct?
If that is correct, would you at least be able to create a PR for the QuasiCallSiteProxy change? Not sure what can be done about the interpretLoop method though |
Btw: I would think that the QuasiCallsite code would only get hit if you're code uses backticks, which, prior to 1.7.14 were just (incorrectly) considered regular string delimiters, but are now (properly) interpreted as Template String Literals As for the too long InterpretLoop method: seems like the resolution would be to extract some logic from the method into helper functions. Haven't looked at potential candidates, but a PR is always welcome |
@rbri could you comment on the getQuasiCallSiteProxy suggestion/approach? I saw you did stuff related to the getRegexProxy fairly recently, so am hoping you might know the purpose of these 'proxies' and whether it makes sense to add one for quasi callsites as well? |
Note: this quasi stuff was renamed into template in commit f797ac8 Regarding the performance - i have no idea why commenting out that code will improve the performance; at least i fear some template constructs are no longer working after that change. And now some words about the regex proxy thingy.... The overall idea is to make the whole RegExp implementation replacable - but this is not so simple like for other classes. The problem is the /regex/ syntax - this is handled by the parser. Therefore we have this strange factory-like pattern that supports
If you like to have a sample - HtmlUnit replaces only the backend (by converting the regex into a java regex) but still uses the js regex part from rhino. And if someday someone merges #1419 i can try to implement a whole new regexp implementation based on a more advanced regexp engine (unicode flag and all the other missing stuff) that replaced the backend and the js part. But i have absolutely no glue why the same approach should work in this case. |
And one more idea: maybe we can improve the template handling in a way that we introduce a separate ast node if a template is a simple (multiline) template (no replacements inside). In this case we can simplify the processing to the same as we do for strings, only the decompiler has to use the ` instead of the ". @gbrail @p-bakker @tuchida @tonygermano - what do you think? |
Hi, here are my guesses |
Will have another look at that after my vacation... |
I am using rhino to calculate a set of float data
when using version 1.7.14, the calculation time is as follows:
and when using version 1.7.12,the calculation time is as follows:
As far as I can see, the 1.7.12 version seems to perform better, is there something wrong with the 1.7.14 version? Or is there any special attention to the use of version 1.7.14?
My equipment and environment:
Rhino used in android device:Google pixel 3XL
Mac book Pro 2022,M2 CPU,16GB memory,OpenJDK 8
The text was updated successfully, but these errors were encountered: