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

compiler: Optimize record updates #6033

Conversation

jhogberg
Copy link
Contributor

#2080 isn't such a bad idea now that we have the JIT and far better type analysis. This PR is a modernized version that improves record update performance by a small but noticeable amount.

@jhogberg jhogberg added team:VM Assigned to OTP team VM enhancement labels May 30, 2022
@jhogberg jhogberg requested a review from bjorng May 30, 2022 12:31
@jhogberg jhogberg self-assigned this May 30, 2022
@github-actions
Copy link
Contributor

github-actions bot commented May 30, 2022

CT Test Results

       5 files     441 suites   1h 18m 20s ⏱️
3 547 tests 3 353 ✔️ 182 💤 12
7 431 runs  7 213 ✔️ 206 💤 12

For more details on these failures, see this check.

Results for commit 85aa2e0.

♻️ This comment has been updated with latest results.

To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass.

See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally.

Artifacts

// Erlang/OTP Github Action Bot

@jhogberg jhogberg force-pushed the john/compiler/optimize-record-updates/OTP-18126 branch from 209f508 to 43592a7 Compare May 30, 2022 14:02
@jhogberg jhogberg force-pushed the john/compiler/optimize-record-updates/OTP-18126 branch from 43592a7 to 5b5be11 Compare May 30, 2022 17:42
lib/compiler/src/beam_call_types.erl Outdated Show resolved Hide resolved
lib/compiler/src/beam_call_types.erl Outdated Show resolved Hide resolved
lib/compiler/src/beam_ssa_type.erl Outdated Show resolved Hide resolved
lib/compiler/src/beam_ssa_codegen.erl Outdated Show resolved Hide resolved
lib/compiler/src/beam_types.erl Show resolved Hide resolved
lib/compiler/src/beam_types.erl Show resolved Hide resolved
lib/compiler/src/beam_call_types.erl Show resolved Hide resolved
@jhogberg jhogberg force-pushed the john/compiler/optimize-record-updates/OTP-18126 branch 5 times, most recently from 5ffc74f to a450a24 Compare May 31, 2022 22:17
@jhogberg
Copy link
Contributor Author

Thanks, I've refactored the changes to will_succeed/3 and improved the test coverage.

@jhogberg jhogberg added testing currently being tested, tag is used by OTP internal CI and removed testing currently being tested, tag is used by OTP internal CI labels Jun 1, 2022
jhogberg added 7 commits June 3, 2022 14:47
We don't need to stash the preserved term if it's currently live,
making the code slightly shorter.
This is needed to keep the type information consistent in an
upcoming commit that optimizes record updates. It will introduce
a psuedo-instruction that does several updates at once, which gets
converted either to a specialized instruction or a series of
`setelement/3` calls during code generation.

As the `setelement/3` is taken through `beam_call_types`, and that
only dealt with normalized types prior to this commit, its type
information would be less precise and could cause validation to
fail.
This instruction updates several tuple fields at once, improving
on the old `setelement/3 + set_tuple_element` method in the
following ways:

* Eliminates BIF call overhead, the tuple is copied and updated
  inline.
* Doesn't require special treatment in the validator.
* Uses heap allocations in the same manner as `put_tuple2` and
  friends.
* When all fields are updated with the same value (runtime check),
  we can set `Dst=Src` and move on with our day. This is impossible
  with `set_tuple_element` as it requires a new copy every time
  to avoid creating illegal references from the old heap to the
  new heap.
@jhogberg jhogberg force-pushed the john/compiler/optimize-record-updates/OTP-18126 branch from a450a24 to 85aa2e0 Compare June 3, 2022 12:51
@jhogberg jhogberg added the testing currently being tested, tag is used by OTP internal CI label Jun 3, 2022
@jhogberg jhogberg added this to the OTP-26.0 milestone Jun 3, 2022
@jhogberg jhogberg merged commit 9b91c7d into erlang:master Jun 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement team:VM Assigned to OTP team VM testing currently being tested, tag is used by OTP internal CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants