Skip to content

Commit 4a2e350

Browse files
temp: Store messages primarily by their signed ID
This change moves our position in an impactful trade-off space in a direction that we will not want to pursue long-term. It does, however, provide significant (as much as 2x, depending on circumstances) performance improvements that are valuable until PR #391 hits. Prior to this commit, the `hb_cache` system referenced all messages via their uncommitted ID, which is linked to from all committed IDs. Each commitment was then stored in the `commitments` key of this message. Upside: A consequence of this design is that reading one ID for a message (whether signed or unsigned) leads to all of the known commitments being available for use. Downside: This design reads _all_ commitments into memory every time a single message is read. While sometimes useful, this is not desirable behavior in all cases. #391 moves us forward with a long-term fix, but until that hits `edge` this PR provides immediate performance relief, while also leading to a modest increase in the size of caches.
1 parent 61c4c8d commit 4a2e350

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/hb_cache.erl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -234,15 +234,15 @@ do_write_message(List, Store, Opts) when is_list(List) ->
234234
do_write_message(Msg, Store, Opts) when is_map(Msg) ->
235235
?event(debug_cache, {writing_message, Msg}),
236236
% Calculate the IDs of the message.
237-
UncommittedID = hb_message:id(Msg, none, Opts#{ linkify_mode => discard }),
238-
AltIDs = calculate_all_ids(Msg, Opts) -- [UncommittedID],
237+
CommittedID = hb_message:id(Msg, signed, Opts#{ linkify_mode => discard }),
238+
AltIDs = calculate_all_ids(Msg, Opts) -- [CommittedID],
239239
MsgHashpathAlg = hb_path:hashpath_alg(Msg, Opts),
240-
?event(debug_cache, {writing_message, {id, UncommittedID}, {alt_ids, AltIDs}, {original, Msg}}),
240+
?event(debug_cache, {writing_message, {id, CommittedID}, {alt_ids, AltIDs}, {original, Msg}}),
241241
% Write all of the keys of the message into the store.
242-
hb_store:make_group(Store, UncommittedID),
242+
hb_store:make_group(Store, CommittedID),
243243
maps:map(
244244
fun(Key, Value) ->
245-
write_key(UncommittedID, Key, MsgHashpathAlg, Value, Store, Opts)
245+
write_key(CommittedID, Key, MsgHashpathAlg, Value, Store, Opts)
246246
end,
247247
maps:without([<<"priv">>], Msg)
248248
),
@@ -252,14 +252,14 @@ do_write_message(Msg, Store, Opts) when is_map(Msg) ->
252252
fun(AltID) ->
253253
?event(debug_cache,
254254
{linking_commitment,
255-
{uncommitted_id, UncommittedID},
256-
{committed_id, AltID}
255+
{committed_id, CommittedID},
256+
{alt_id, AltID}
257257
}),
258-
hb_store:make_link(Store, UncommittedID, AltID)
258+
hb_store:make_link(Store, CommittedID, AltID)
259259
end,
260260
AltIDs
261261
),
262-
{ok, UncommittedID}.
262+
{ok, CommittedID}.
263263

264264
%% @doc Write a single key for a message into the store.
265265
write_key(Base, <<"commitments">>, _HPAlg, RawCommitments, Store, Opts) ->

0 commit comments

Comments
 (0)