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

Cache router, filter, and process handlers into funs #4068

Merged
merged 1 commit into from
Jul 27, 2023

Conversation

NelsonVides
Copy link
Collaborator

Following the advise from https://www.erlang.org/doc/efficiency_guide/functions.html#function-calls

Caching callback functions into funs may be more efficient in the long run than apply calls for frequently-used callbacks.

Similar logic was applied in OTP itself in
erlang/otp#5831
erlang/otp#7419

@mongoose-im

This comment was marked as outdated.

@NelsonVides NelsonVides force-pushed the cache_routing_callbacks branch 2 times, most recently from 6c0b647 to da68910 Compare July 26, 2023 14:00
@mongoose-im

This comment was marked as outdated.

@codecov
Copy link

codecov bot commented Jul 26, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (3e8bcca) 83.89% compared to head (c7074ee) 83.90%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4068   +/-   ##
=======================================
  Coverage   83.89%   83.90%           
=======================================
  Files         526      526           
  Lines       33168    33172    +4     
=======================================
+ Hits        27826    27832    +6     
+ Misses       5342     5340    -2     
Files Changed Coverage Δ
src/config/mongoose_config_spec.erl 100.00% <ø> (ø)
src/ejabberd_router.erl 78.40% <100.00%> (-0.18%) ⬇️
src/mongoose_packet_handler.erl 100.00% <100.00%> (ø)
src/mongoose_router.erl 87.50% <100.00%> (+1.78%) ⬆️
src/xmpp_router.erl 100.00% <100.00%> (ø)

... and 7 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Following the advise from https://www.erlang.org/doc/efficiency_guide/functions.html#function-calls
> Caching callback functions into funs may be more efficient in the long run than apply calls for frequently-used callbacks.
@mongoose-im
Copy link
Collaborator

mongoose-im commented Jul 26, 2023

elasticsearch_and_cassandra_25 / elasticsearch_and_cassandra_mnesia / c7074ee
Reports root/ big
OK: 369 / Failed: 0 / User-skipped: 38 / Auto-skipped: 0


small_tests_24 / small_tests / c7074ee
Reports root / small


small_tests_25 / small_tests / c7074ee
Reports root / small


small_tests_25_arm64 / small_tests / c7074ee
Reports root / small


ldap_mnesia_24 / ldap_mnesia / c7074ee
Reports root/ big
OK: 2258 / Failed: 0 / User-skipped: 827 / Auto-skipped: 0


dynamic_domains_pgsql_mnesia_24 / pgsql_mnesia / c7074ee
Reports root/ big
OK: 4221 / Failed: 0 / User-skipped: 82 / Auto-skipped: 0


ldap_mnesia_25 / ldap_mnesia / c7074ee
Reports root/ big
OK: 2257 / Failed: 1 / User-skipped: 827 / Auto-skipped: 0

mod_global_distrib_SUITE:hosts_refresher:test_host_refreshing
{error,
  {{trees_for_connections_present,true,[{times,100,false}],ok},
   [{mongoose_helper,do_wait_until,2,
      [{file,"/home/circleci/project/big_tests/tests/mongoose_helper.erl"},
       {line,357}]},
    {mod_global_distrib_SUITE,test_host_refreshing,1,
      [{file,
         "/home/circleci/project/big_tests/tests/mod_global_distrib_SUITE.erl"},
       {line,384}]},
    {test_server,ts_tc,3,[{file,"test_server.erl"},{line,1782}]},
    {test_server,run_test_case_eval1,6,
      [{file,"test_server.erl"},{line,1291}]},
    {test_server,run_test_case_eval,9,
      [{file,"test_server.erl"},{line,1223}]}]}}

Report log


dynamic_domains_mssql_mnesia_25 / odbc_mssql_mnesia / c7074ee
Reports root/ big
OK: 4218 / Failed: 0 / User-skipped: 85 / Auto-skipped: 0


dynamic_domains_pgsql_mnesia_25 / pgsql_mnesia / c7074ee
Reports root/ big
OK: 4221 / Failed: 0 / User-skipped: 82 / Auto-skipped: 0


dynamic_domains_mysql_redis_25 / mysql_redis / c7074ee
Reports root/ big
OK: 4195 / Failed: 0 / User-skipped: 108 / Auto-skipped: 0


pgsql_mnesia_24 / pgsql_mnesia / c7074ee
Reports root/ big
OK: 4604 / Failed: 0 / User-skipped: 89 / Auto-skipped: 0


internal_mnesia_25 / internal_mnesia / c7074ee
Reports root/ big
OK: 2404 / Failed: 0 / User-skipped: 681 / Auto-skipped: 0


pgsql_mnesia_25 / pgsql_mnesia / c7074ee
Reports root/ big
OK: 4604 / Failed: 0 / User-skipped: 89 / Auto-skipped: 0


mysql_redis_25 / mysql_redis / c7074ee
Reports root/ big
OK: 4590 / Failed: 0 / User-skipped: 103 / Auto-skipped: 0


mssql_mnesia_25 / odbc_mssql_mnesia / c7074ee
Reports root/ big
OK: 4601 / Failed: 0 / User-skipped: 92 / Auto-skipped: 0


ldap_mnesia_25 / ldap_mnesia / c7074ee
Reports root/ big
OK: 2257 / Failed: 1 / User-skipped: 827 / Auto-skipped: 0

mod_global_distrib_SUITE:hosts_refresher:test_host_refreshing
{error,
  {{trees_for_connections_present,true,[{times,100,false}],ok},
   [{mongoose_helper,do_wait_until,2,
      [{file,"/home/circleci/project/big_tests/tests/mongoose_helper.erl"},
       {line,357}]},
    {mod_global_distrib_SUITE,test_host_refreshing,1,
      [{file,
         "/home/circleci/project/big_tests/tests/mod_global_distrib_SUITE.erl"},
       {line,384}]},
    {test_server,ts_tc,3,[{file,"test_server.erl"},{line,1782}]},
    {test_server,run_test_case_eval1,6,
      [{file,"test_server.erl"},{line,1291}]},
    {test_server,run_test_case_eval,9,
      [{file,"test_server.erl"},{line,1223}]}]}}

Report log


ldap_mnesia_25 / ldap_mnesia / c7074ee
Reports root/ big
OK: 2258 / Failed: 0 / User-skipped: 827 / Auto-skipped: 0

@NelsonVides NelsonVides marked this pull request as ready for review July 27, 2023 13:21
Copy link
Contributor

@arcusfelis arcusfelis left a comment

Choose a reason for hiding this comment

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

yea, probably marginally faster.
but only because we store it in a persistent term.

If it was in ETS table than copying a bigger term would defeat the gains :D

@arcusfelis arcusfelis merged commit 4333abe into master Jul 27, 2023
4 checks passed
@arcusfelis arcusfelis deleted the cache_routing_callbacks branch July 27, 2023 13:44
@chrzaszcz chrzaszcz added this to the 6.2.0 milestone Dec 11, 2023
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

4 participants