Skip to content

Reorganize mrb_cache_entry and mrb_method_t types#6220

Merged
matz merged 1 commit into
mruby:masterfrom
dearblue:methodcache
Mar 31, 2024
Merged

Reorganize mrb_cache_entry and mrb_method_t types#6220
matz merged 1 commit into
mruby:masterfrom
dearblue:methodcache

Conversation

@dearblue

Copy link
Copy Markdown
Contributor

The purpose is to remove the mid field from the mrb_cache_entry structure. The resulting RAM requirement for the method cache is reduced from 5 words per entry to 4 words per entry for 32-bit CPUs.

The relevant changes are as follows:

  • Removed MRB_USE_METHOD_T_STRUCT.

    The mrb_method_t type is now always defined as a structure.

  • Include method IDs in mrb_method_t

    Change the flags member to uint32_t. The bitstring structure should be the same as the keys of the mt table in class.c.

I believe the impact on API compatibility with previous versions is minimal.


Attached is a benchmark comparison for your reference.
The targets are (1) the current master, (2) this PR, (3) another alternative and (4) 3.3.0.
Another alternative is to move the bits embedded in struct mrb_cache_entry::mid to struct mrb_cache_entry::c0 (like "word-boxing"). Link to difference.

bm-result-20240330T184902

The purpose is to remove the `mid` field from the `mrb_cache_entry` structure.
The resulting RAM requirement for the method cache is reduced from 5 words per entry to 4 words per entry for 32-bit CPUs.

The relevant changes are as follows:

  - Removed `MRB_USE_METHOD_T_STRUCT`.

    The `mrb_method_t` type is now always defined as a structure.

  - Include method IDs in `mrb_method_t`

    Change the `flags` member to `uint32_t`.
    The bitstring structure should be the same as the keys of the `mt` table in `class.c`.

I believe the impact on API compatibility with previous versions is minimal.
@dearblue

Copy link
Copy Markdown
Contributor Author

The following is the number of CPU cycles obtained from valgrind --tool=cachegrind -- bin/mruby benchmark/bm_fib.rb.
The order of the lines is the same as in the previous benchmark.
The first group is the results from gcc13 -O3 and the second group is the results from gcc13 -Os.

40,186,751,990 (100.0%)  PROGRAM TOTALS         master
40,656,510,074 (100.0%)  PROGRAM TOTALS         this PR
40,733,987,325 (100.0%)  PROGRAM TOTALS         another alternative
40,577,677,399 (100.0%)  PROGRAM TOTALS         3.3.0

61,020,950,744 (100.0%)  PROGRAM TOTALS         master
61,021,647,478 (100.0%)  PROGRAM TOTALS         this PR
61,177,299,954 (100.0%)  PROGRAM TOTALS         another alternative
61,333,670,456 (100.0%)  PROGRAM TOTALS         3.3.0

# I only recently learned about the role and usage of Cachegrind from the SQLite documentation.

@matz
matz merged commit 4230263 into mruby:master Mar 31, 2024
matz added a commit that referenced this pull request Apr 2, 2024
- MRB_METHOD_CFUNC_P: reduce ternary; use logical-or instead
- MRB_METHOD_CFUNC: assume MRB_METHOD_CFUNC_P check before call
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants