Skip to content
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 beautifyjs function make script invoke timeout #120

Open
hlzhang123 opened this issue Oct 12, 2021 · 3 comments
Open

the beautifyjs function make script invoke timeout #120

hlzhang123 opened this issue Oct 12, 2021 · 3 comments

Comments

@hlzhang123
Copy link

we find when the script contains multiline comments were invoke by scriptEngine, before invoked,the beautify funtion decrease the tps

@mxro
Copy link
Collaborator

mxro commented Oct 12, 2021

Thank you for raising this issue!

Is the problem you encounter that when a script contains multiline comments that the processing time for the script increases? Could you provide an example for a script?

Would it be possible to remove comments from the script before running it?

@hlzhang123
Copy link
Author

Thank you for raising this issue!

Is the problem you encounter that when a script contains multiline comments that the processing time for the script increases? Could you provide an example for a script?

Would it be possible to remove comments from the script before running it?
thanks for your response ~~
String js=
"\n" +
// "// ;\n" +
// "// ;\n" +
// "// ;\n" +
// "// ;\n" +
"\n" +
"var timestamp = new Date().getTime() + '';\n" +
"$log.info("timestamp{}", timestamp)\n" +
"\n" +
"var ArrayType = Java.type("java.lang.Object[]");\n" +
"\n" +
"var arr = new ArrayType(3);\n" +
"var testList = [{\n" +
" name: "123"\n" +
"}];\n" ;

the multiline //:\n comment canceled will be increase the script invoked tps;
the script above can be tested by JMC flight record .

"Would it be possible to remove comments from the script before running it?"——sometimes addtional funtions may be commented for use in future !

@mxro
Copy link
Collaborator

mxro commented Oct 24, 2021

@hlzhang123 Thank you for providing the sample code. I have created a new branch and put some of the code into there:

https://github.com/javadelight/delight-nashorn-sandbox/compare/issue-120?expand=1

Could you expand on the unit test I put there to show the problem?

Btw, the sandbox generates the following code from the one provided:

0    [main] DEBUG delight.nashornsandbox.NashornSandbox  - --- Running JS ---
0    [main] DEBUG delight.nashornsandbox.NashornSandbox  - Object.defineProperty(this, 'engine', {});Object.defineProperty(this, 'context', {});delete this.__noSuchProperty__;// ;
// ;
// ;
// ;
var timestamp = new Date().getTime() + '';
print("timestamp{}", timestamp)
var ArrayType = Java.type("java.lang.Object[]");
var arr = new ArrayType(3);
var testList = [{
 name: "123"
}];
1    [main] DEBUG delight.nashornsandbox.NashornSandbox  - --- JS END ---
timestamp{} 1635109014850

So it looks like the comments are not removed as they should according to this class: https://github.com/javadelight/delight-nashorn-sandbox/blob/master/src/main/java/delight/nashornsandbox/internal/RemoveComments.java ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants