From 6189d6d9c9cfda41b5ea3f2a8e2e7ec6cb88e1d6 Mon Sep 17 00:00:00 2001 From: Nelson Vides Date: Tue, 26 Apr 2022 12:33:48 +0200 Subject: [PATCH] Skip to_binary, field is not used By now we have a pretty printer in the logger, and creating accumulators is a hot operation, so we can skip this field when it is not needed. --- src/mongoose_acc.erl | 12 ++++-------- test/json_formatter_SUITE.erl | 11 ++++------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/mongoose_acc.erl b/src/mongoose_acc.erl index 6af5c572786..297ee27189f 100644 --- a/src/mongoose_acc.erl +++ b/src/mongoose_acc.erl @@ -81,7 +81,6 @@ timestamp := integer(), %microsecond origin_pid := pid(), origin_location := location(), - origin_stanza := binary() | undefined, stanza := stanza_metadata() | undefined, lserver := jid:lserver(), host_type := binary() | undefined, @@ -124,11 +123,10 @@ -spec new(Params :: new_acc_params()) -> t(). new(#{ location := Location, lserver := LServer } = Params) -> - {ElementBin, Stanza} = - case maps:get(element, Params, undefined) of - undefined -> {undefined, undefined}; - Element -> {exml:to_binary(Element), stanza_from_params(Params)} - end, + Stanza = case maps:get(element, Params, undefined) of + undefined -> undefined; + _Element -> stanza_from_params(Params) + end, HostType = get_host_type(Params), #{ mongoose_acc => true, @@ -136,7 +134,6 @@ new(#{ location := Location, lserver := LServer } = Params) -> timestamp => os:system_time(microsecond), origin_pid => self(), origin_location => Location, - origin_stanza => ElementBin, stanza => Stanza, lserver => LServer, host_type => HostType, @@ -341,7 +338,6 @@ default_non_strippable() -> timestamp, origin_pid, origin_location, - origin_stanza, stanza, lserver, host_type, diff --git a/test/json_formatter_SUITE.erl b/test/json_formatter_SUITE.erl index 3dcbfa17131..deffa3265c2 100644 --- a/test/json_formatter_SUITE.erl +++ b/test/json_formatter_SUITE.erl @@ -346,6 +346,9 @@ large_event_dont_crash_formatter(_Config) -> %% example_acc(Body) -> + Elem = {xmlel, <<"message">>, + [{<<"type">>, <<"chat">>}, {<<"id">>, <<"1111">>}], + [{xmlel, <<"body">>,[], [{xmlcdata, Body}]}]}, #{lserver => <<"localhost">>, mongoose_acc => true, non_strippable => [], @@ -353,14 +356,8 @@ example_acc(Body) -> line => 116, mfa => {ejabberd_router,route,3}}, origin_pid => self(), - origin_stanza => <<"", - Body/binary, - "">>, ref => make_ref(), - stanza => #{element => {xmlel,<<"message">>, - [{<<"type">>,<<"chat">>},{<<"id">>,<<"1111">>}], - [{xmlel,<<"body">>,[], - [{xmlcdata,Body}]}]}, + stanza => #{element => Elem, from_jid => {jid,<<"userA">>,<<"localhost">>,<<>>,<<"usera">>,<<"localhost">>,<<>>}, name => <<"message">>, ref => make_ref(),