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

Change the OFFSETCLOSURE(2|M2) bytecode instructions to use an offset of 3 instead #10050

Merged
merged 2 commits into from Nov 26, 2020

Conversation

Ekdohibs
Copy link
Contributor

This change is to match the new representation of closures, which has a step of 3 instead of 2.

@gasche
Copy link
Member

gasche commented Nov 26, 2020

The change looks obviously correct. There was a special opcode for a common case of field-access-in-a-closure that was detected and generated on the fly. The new closure representation means that the offset-of-interest is 3, not 2 anymore, but the code was not changed when this happened. There was no bug, but the optimization would (probably) not apply anymore so the special opcode was useless. The PR changes the special opcode to apply to offsets of 3 instead of 2, to re-enable the specialized encoding in the same situations.

Questions (not necessarily for @Ekdohibs):

  • Can we in fact still see a performance advantage to this specialized instruction? (Presumably the current 'trunk' (and 4.12 ?) state would have a performance regression for bytecode programs that we have not noticed.)
  • Does this change in opcode name+semantics affect js_of_ocaml? Should something change there?
  • Could we have caught the un-optimization earlier with testsuite support? Should we invest in checking that those custom opcodes are indeed used in the source programs where we believe they should?

Copy link
Contributor

@xavierleroy xavierleroy left a comment

Choose a reason for hiding this comment

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

Well spotted, and thanks for the patch. It looks good to me.

@Ekdohibs
Copy link
Contributor Author

Concerning spotting the un-optimization, there are two testcases that seem to be designed those opcodes (t251-pushoffsetclosure2.ml and t251-pushoffsetclosurem2.ml), but where the generated bytecode is only in a comment and not tested for containing the optimized instructions.

@xavierleroy
Copy link
Contributor

Presumably the current 'trunk' (and 4.12 ?) state would have a performance regression for bytecode programs that we have not noticed.

Presumably, although it may be hard to measure. But I guess the code size of the bootstrap compiler (boot/ocamlc) increased when bootstrapping the change of closure representation, as the +2/-2 instructions were no longer generated because the offsets jumped to +3/-3.

Does this change in opcode name+semantics affect js_of_ocaml? Should something change there?

Good question. Who is our liaison agent with js_of_ocaml, again?

Could we have caught the un-optimization earlier with testsuite support?

That's the general issue of CI to monitor performance. There are more egregious cases of performance regression.

Should we invest in checking that those custom opcodes are indeed used in the source programs where we believe they should?

No, this sounds too specific to me. We test for functional correctness first and foremost, and for overall performance if only we knew how to test for that. Testing whether a specific optimization triggers comes as a distant third or fourth.

@nojb
Copy link
Contributor

nojb commented Nov 26, 2020

Does this change in opcode name+semantics affect js_of_ocaml? Should something change there?

Good question. Who is our liaison agent with js_of_ocaml, again?

cc @hhugo

@xavierleroy
Copy link
Contributor

there are two testcases that seem to be designed those opcodes (t251-pushoffsetclosure2.ml and t251-pushoffsetclosurem2.ml)

You're right. I think these tests are supposed to exercise all opcodes, but they are "only" checked for functional correctness (does the generated bytecode work?).

@gasche
Copy link
Member

gasche commented Nov 26, 2020

Would it be hard/costly/annoying to just add dynamic checks that the testsuite tests are really generating the opcodes we expect them to? This would catch similar potential issues with the opcodes that are only generated by peephole-style detection.

@xavierleroy
Copy link
Contributor

@Octachron : are you OK with having this change in 4.12? It's not really a bug fix but it corrects an omission in the implementation of the new closure format.

@Octachron
Copy link
Member

It sounds indeed better in term of maintenance complexity to not have a gap between the change between the closure format and the associated bytecode instructions.

@xavierleroy
Copy link
Contributor

OK, I'll put it in the 4.12 section of Changes and cherry-pick.

@xavierleroy xavierleroy merged commit 4f732e3 into ocaml:trunk Nov 26, 2020
xavierleroy pushed a commit that referenced this pull request Nov 26, 2020
…instead of 2 (#10050)

Replace (PUSH)OFFSETCLOSURE(2|M2) by (PUSH)OFFSETCLOSURE(3|M3) to match the change of representation of closures.

(cherry picked from commit 4f732e3)
@Ekdohibs Ekdohibs deleted the offsetclosure branch November 27, 2020 07:57
dbuenzli pushed a commit to dbuenzli/ocaml that referenced this pull request Mar 25, 2021
…instead of 2 (ocaml#10050)

Replace (PUSH)OFFSETCLOSURE(2|M2) by (PUSH)OFFSETCLOSURE(3|M3) to match the change of representation of closures.
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.

None yet

5 participants