A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
perf(gateway): raise binary vheap floor for large guilds (#3831)
Hampus7b0c5ccb91f3
diff --git a/fluxer_gateway/src/guild/guild.erl b/fluxer_gateway/src/guild/guild.erlindex 922be0f1c..0796542ab 100644--- a/fluxer_gateway/src/guild/guild.erl+++ b/fluxer_gateway/src/guild/guild.erl@@ -10,6 +10,8 @@-define(HIBERNATE_AFTER_MS, 15000).-define(FULLSWEEP_AFTER, 100).+-define(LARGE_GUILD_MEMBERS, 10000).+-define(LARGE_GUILD_MIN_BIN_VHEAP_WORDS, 16_000_000).-type guild_state() :: map().-type call_reply() ::@@ -35,6 +37,7 @@ init(GuildState) ->State0 = guild_init:init_base_state(GuildState),State1 = guild_init:init_member_list(State0),State2 = guild_init:init_counts(State1),+ ok = apply_gc_tuning(State2),State3 = guild_init:init_caches_and_timers(State2),State4 = guild_init:init_voice_server(State3),erlang:garbage_collect(),@@ -488,9 +491,20 @@ terminate(_Reason, _State) ->-spec code_change(term(), guild_state(), term()) -> {ok, guild_state()}.code_change(_OldVsn, State, _Extra) ->erlang:process_flag(fullsweep_after, ?FULLSWEEP_AFTER),+ ok = apply_gc_tuning(State),erlang:garbage_collect(),{ok, State}.+-spec apply_gc_tuning(guild_state()) -> ok.+apply_gc_tuning(State) ->+ case maps:get(member_count, State, 0) of+ Count when is_integer(Count), Count >= ?LARGE_GUILD_MEMBERS ->+ _ = erlang:process_flag(min_bin_vheap_size, ?LARGE_GUILD_MIN_BIN_VHEAP_WORDS),+ ok;+ _ ->+ ok+ end.+-spec retire_thread_store(term(), guild_state()) -> ok.retire_thread_store(Tab, State) ->case maps:get(thread_store, maps:get(data, State, #{}), undefined) of