Skip to content

Comparison and object operations. - #2475

Merged
gbrail merged 1 commit into
mozilla:masterfrom
aardvark179:aardvark179-v2-instructions-2
Sep 17, 2026
Merged

gbrail merged 1 commit into
mozilla:masterfrom
aardvark179:aardvark179-v2-instructions-2

Conversation

@aardvark179

Copy link
Copy Markdown
Contributor

Next set of instructions, comparison, equality, and types and instance of operations.

@gbrail gbrail left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both of these small things were found by AI but I verified them. Both affect performance but after all that's what we're trying to accomplish here. If you'd rather take care of them some other time (or not at all) that's OK too.

{
number_compare:
{
Number rNum, lNum;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if DOUBLE_MARK is true for both lhs and rhs we are missing a big optimization opportunity to do the comparison without any boxing. This would require adding a "compare" function in ScriptRuntime that takes two doubles as arguments, but it would prevent us from undoing the optimizations that we got. OTOH I don't know how much the interpreter uses the ability to avoid boxing of doubles, since the compiler does that by generating different bytecode.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.


@Override
public void interpret(Context cx, CallFrameV2 frame) {
frame.push(ScriptRuntime.typeofName(frame.scope, name));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ScriptRuntime.typeofName calls Context.getContext(). Since you have the context already you can save a thread-local variable lookup if you use "cx".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@aardvark179
aardvark179 force-pushed the aardvark179-v2-instructions-2 branch from b62132b to 0a66ebe Compare September 6, 2026 18:32
@aardvark179

Copy link
Copy Markdown
Contributor Author

Thanks for spotting those @gbrail, while fixing them I also moved a couple of switch statements over to switch expressions, since I was touching those areas of the code anyway.

@aardvark179
aardvark179 force-pushed the aardvark179-v2-instructions-2 branch from 0a66ebe to 86675fb Compare September 14, 2026 09:06
@aardvark179

Copy link
Copy Markdown
Contributor Author

BTW @gbrail I got my robot friend to apply the review comments from this and the previous instruction PR to all of the other instruction commits. I've put everything on https://github.com/aardvark179/rhino/tree/aardvark179-interpreterv2 (the branch for #2426). I don't see the test failure on that PR locally, but I have found various ways to push similar scripts over the edge and cause a stack overflow in node transformation—I can cause the same issues with V1 and class compilation. I'm going to try some refactoring to reduce the problem in node transformation and then see if I can provoke the issue in code gen as well.

@gbrail

gbrail commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator

Thanks, looking good!

@gbrail
gbrail merged commit 7de370f into mozilla:master Sep 17, 2026
12 checks passed
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

Successfully merging this pull request may close these issues.

2 participants