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

Elide duplicate OP_source_loc opcodes #916

Closed
bnoordhuis opened this issue Feb 14, 2025 · 1 comment
Closed

Elide duplicate OP_source_loc opcodes #916

bnoordhuis opened this issue Feb 14, 2025 · 1 comment
Labels
enhancement New feature or request

Comments

@bnoordhuis
Copy link
Contributor

Example phase 1 bytecode:

;;     print("done")

        source_loc      6:5
        scope_get_var   print,1
        source_loc      6:5       ;; duplicate
        push_atom_value done
        call            1
        drop       

Not really a bug, just mildly inefficient. All what emitting the same location twice accomplishes is bloating the bytecode.

Probably easy to fix by remembering the last emitted source location.

@bnoordhuis bnoordhuis added the enhancement New feature or request label Feb 14, 2025
bnoordhuis added a commit to bnoordhuis/quickjs that referenced this issue Feb 14, 2025
Requires a little extra bookkeeping but there are two good reasons to
accept that overhead:

1. OP_source_loc is pretty big at 9 bytes so duplicates bloat the
   bytecode considerably

2. An OP_source_loc opcode can throw off the peephole optimizer if it's
   between two opcodes the optimizer is trying to match; removing
   duplicates reduces the chance of that happening

Fixes: quickjs-ng#916
@bnoordhuis
Copy link
Contributor Author

Closing, in the end not merged because of #917 (comment).

@bnoordhuis bnoordhuis closed this as not planned Won't fix, can't repro, duplicate, stale Feb 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant