Skip to content

JIT: Optimize creation of binaries #6031

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

Merged
merged 3 commits into from
Jun 8, 2022

Conversation

bjorng
Copy link
Contributor

@bjorng bjorng commented May 30, 2022

In the JIT, improve the code generation for binary construction for segments of fixed widths of no more than 64 bits and for variable width segments that are a set to 0.

I have run the benchmark linked to from #5639.

On my Intel iMac from 2017, the result without this pull request was:

    == Testing with 1 MB ==
    fun base64:encode/1: 1000 iterations in 16264 ms: 61 it/sec
    fun base64:decode/1: 1000 iterations in 18597 ms: 53 it/sec

With this pull request:

    == Testing with 1 MB ==
    fun base64:encode/1: 1000 iterations in 10955 ms: 91 it/sec
    fun base64:decode/1: 1000 iterations in 10629 ms: 94 it/sec

On my M1 MacBook Pro from 2020 the result before was:

    == Testing with 1 MB ==
    fun base64:encode/1: 1000 iterations in 12299 ms: 81 it/sec
    fun base64:decode/1: 1000 iterations in 15147 ms: 66 it/sec

After:

    == Testing with 1 MB ==
    fun base64:encode/1: 1000 iterations in 8550 ms: 116 it/sec
    fun base64:decode/1: 1000 iterations in 10066 ms: 99 it/sec

bjorng added 2 commits May 30, 2022 06:53
While at it, also update the comments, removing mentions of
old and new instruction sets. (The old instruction set was removed
a long time ago.)
Useful for the JIT because it has fewer arguments and thus can be
called using fewer instructions.
@bjorng bjorng added team:VM Assigned to OTP team VM enhancement testing currently being tested, tag is used by OTP internal CI labels May 30, 2022
@bjorng bjorng requested review from garazdawi and jhogberg May 30, 2022 06:02
@bjorng bjorng self-assigned this May 30, 2022
@github-actions
Copy link
Contributor

github-actions bot commented May 30, 2022

CT Test Results

       3 files     125 suites   37m 44s ⏱️
1 451 tests 1 409 ✔️ 42 💤 0
1 751 runs  1 692 ✔️ 59 💤 0

Results for commit e5bd2c1.

♻️ 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

@bjorng bjorng force-pushed the bjorn/jit/bs_create_bin branch from 8bf949d to 442cbff Compare May 30, 2022 07:11
@bjorng bjorng force-pushed the bjorn/jit/bs_create_bin branch 8 times, most recently from 845d29a to 69edb96 Compare June 2, 2022 12:07
@bjorng bjorng force-pushed the bjorn/jit/bs_create_bin branch 4 times, most recently from 06f4a21 to afd33b8 Compare June 7, 2022 05:25
@bjorng bjorng added this to the OTP-26.0 milestone Jun 7, 2022
mov_imm(ARG3, seg.effectiveSize);
} else if (seg.unit == 0) {
/* Silly but legal. */
mov_imm(ARG3, 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

According to gcov, this line is never run. Is that because the compiler will never emit such code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Contrary to the comment, a unit size of zero is not legal (at least for integer segments). I have removed the code.

@@ -1596,8 +1638,200 @@ struct BscSegment {

Uint error_info;
Sint effectiveSize;
enum class action { NONE, ACCUMULATE_FIRST, ACCUMULATE, STORE } action;
Copy link
Contributor

Choose a reason for hiding this comment

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

Would you mind adding a small description what the different actions do and when they trigger?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have renamed NONE to DIRECT and added more comments.

@bjorng bjorng force-pushed the bjorn/jit/bs_create_bin branch 2 times, most recently from 199ada3 to e5bd2c1 Compare June 7, 2022 12:48
In the JIT, improve the code generation for binary construction
for segments of fixed widths of no more than 64 bits and for
variable width segments that are a set to 0.

I have run the benchmark linked to from erlang#5639.

On my Intel iMac from 2017, the result without this commit was:

    == Testing with 1 MB ==
    fun base64:encode/1: 1000 iterations in 16264 ms: 61 it/sec
    fun base64:decode/1: 1000 iterations in 18597 ms: 53 it/sec

With this commit:

    == Testing with 1 MB ==
    fun base64:encode/1: 1000 iterations in 10955 ms: 91 it/sec
    fun base64:decode/1: 1000 iterations in 10629 ms: 94 it/sec

On my M1 MacBook Pro from 2020 the result before was:

    == Testing with 1 MB ==
    fun base64:encode/1: 1000 iterations in 12299 ms: 81 it/sec
    fun base64:decode/1: 1000 iterations in 15147 ms: 66 it/sec

After:

    == Testing with 1 MB ==
    fun base64:encode/1: 1000 iterations in 8550 ms: 116 it/sec
    fun base64:decode/1: 1000 iterations in 10066 ms: 99 it/sec
@bjorng bjorng force-pushed the bjorn/jit/bs_create_bin branch from e5bd2c1 to 6fc65ab Compare June 8, 2022 08:00
@bjorng bjorng merged commit 3e73fea into erlang:master Jun 8, 2022
@bjorng bjorng deleted the bjorn/jit/bs_create_bin branch June 8, 2022 08:08
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