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

H-3707, H-3708: Implement libp2p frontend #5761

Merged
merged 19 commits into from
Dec 3, 2024

Conversation

indietyp
Copy link
Member

@indietyp indietyp commented Dec 1, 2024

🌟 What is the purpose of this PR?

This implements the libp2p frontend, that is used to connect and interact with the underlying libp2p implementation.

This was initially split up into multiple tasks, but they have been merged into one, as keeping them separate was a bit more of a challenge than it should have been.

Care has been taken that the effect code and non effect code (like logging) integrate properly.

Pre-Merge Checklist 🚀

🚢 Has this modified a publishable library?

This PR:

  • does not modify any publishable blocks or libraries, or modifications do not need publishing

📜 Does this require a change to the docs?

The changes in this PR:

  • are internal and do not require a docs change

🕸️ Does this require a change to the Turbo Graph?

The changes in this PR:

  • do not affect the execution graph

@github-actions github-actions bot added area/deps Relates to third-party dependencies (area) area/libs Relates to first-party libraries/crates/packages (area) type/eng > backend Owned by the @backend team area/tests New or updated tests labels Dec 1, 2024
@indietyp indietyp marked this pull request as draft December 1, 2024 19:58
Copy link

codecov bot commented Dec 1, 2024

Codecov Report

Attention: Patch coverage is 17.17172% with 164 lines in your changes missing coverage. Please review.

Project coverage is 23.07%. Comparing base (863d181) to head (fb6e710).
Report is 498 commits behind head on main.

Files with missing lines Patch % Lines
...lient/typescript/src/net/internal/networkLogger.ts 8.64% 74 Missing ⚠️
...ocal/harpc/client/typescript/src/net/Connection.ts 10.00% 63 Missing ⚠️
...pc/client/typescript/src/net/internal/transport.ts 9.09% 10 Missing ⚠️
...l/harpc/client/typescript/src/net/NetworkLogger.ts 30.76% 9 Missing ⚠️
...s/@local/harpc/client/typescript/src/net/Client.ts 50.00% 4 Missing ⚠️
...cal/harpc/client/typescript/src/net/Transaction.ts 62.50% 3 Missing ⚠️
...local/harpc/client/typescript/src/net/Transport.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5761      +/-   ##
==========================================
- Coverage   23.12%   23.07%   -0.05%     
==========================================
  Files         561      568       +7     
  Lines       18913    19103     +190     
  Branches     2680     2697      +17     
==========================================
+ Hits         4373     4408      +35     
- Misses      14488    14643     +155     
  Partials       52       52              
Flag Coverage Δ
apps.hash-ai-worker-ts 1.32% <ø> (ø)
apps.hash-api 1.16% <ø> (ø)
local.harpc-client 65.18% <17.17%> (-6.85%) ⬇️
local.hash-backend-utils 8.80% <ø> (ø)
local.hash-graph-sdk 100.00% <ø> (ø)
local.hash-isomorphic-utils 1.03% <ø> (ø)
local.hash-subgraph 24.54% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

CiaranMn
CiaranMn previously approved these changes Dec 3, 2024
Copy link
Member

@CiaranMn CiaranMn left a comment

Choose a reason for hiding this comment

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

Cool :)

One comment I think probably doesn't make any practical difference, just writing it because I thought it, can be ignored

Comment on lines 23 to 64
interface Instruction {
type: string; // single alpha character
}
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if either of these are important if this interface is never going to be exposed outside the file, but:

  1. Could move the comment so that the fact that it's a single alpha character is available in editor hints at the point of use
Suggested change
interface Instruction {
type: string; // single alpha character
}
interface Instruction {
/** single alpha character */
type: string;
}
  1. The set of possible values is small enough to type directly, but might be more annoying to use than is worth it
Suggested change
interface Instruction {
type: string; // single alpha character
}
type AlphaCharacter = "a" | "b" | "c" | "d" | "e" | "f"; // etc
interface Instruction {
/** single alpha character */
type: AlphaCharacter | Uppercase<AlphaCharacter>;
}

Copy link
Member Author

@indietyp indietyp Dec 3, 2024

Choose a reason for hiding this comment

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

I thought about doing (2) but then stopped as writing out 26 characters seemed a bit repetitive for an internal only thing. Although probably worth the typing affordances it gives. Considering that this is partially exposed to the user (if they want to extend it / modify it) I added more strict typing to ensure that everything is well-formed, see: 81f7e5f

@indietyp indietyp force-pushed the bm/h-3707-typescript-libp2p-implementation branch from 09344bd to 2d9f6d5 Compare December 3, 2024 11:05
@indietyp indietyp added this pull request to the merge queue Dec 3, 2024
Copy link
Contributor

github-actions bot commented Dec 3, 2024

Benchmark results

@rust/hash-graph-benches – Integrations

representative_read_entity

Function Value Mean Flame graphs
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/building/v/1 $$16.3 \mathrm{ms} \pm 199 \mathrm{μs}\left({\color{lightgreen}-35.647 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/song/v/1 $$15.7 \mathrm{ms} \pm 186 \mathrm{μs}\left({\color{lightgreen}-8.861 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/book/v/1 $$16.8 \mathrm{ms} \pm 240 \mathrm{μs}\left({\color{gray}-2.223 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/page/v/2 $$16.7 \mathrm{ms} \pm 202 \mathrm{μs}\left({\color{lightgreen}-7.047 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/uk-address/v/1 $$16.9 \mathrm{ms} \pm 210 \mathrm{μs}\left({\color{gray}-0.035 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/playlist/v/1 $$16.2 \mathrm{ms} \pm 210 \mathrm{μs}\left({\color{lightgreen}-12.209 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/person/v/1 $$18.5 \mathrm{ms} \pm 231 \mathrm{μs}\left({\color{red}7.68 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/organization/v/1 $$16.1 \mathrm{ms} \pm 184 \mathrm{μs}\left({\color{gray}-2.740 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/block/v/1 $$17.1 \mathrm{ms} \pm 202 \mathrm{μs}\left({\color{gray}-4.102 \mathrm{\%}}\right) $$ Flame Graph

representative_read_multiple_entities

Function Value Mean Flame graphs
entity_by_property depths: DT=255, PT=255, ET=255, E=255 $$66.6 \mathrm{ms} \pm 463 \mathrm{μs}\left({\color{gray}-3.697 \mathrm{\%}}\right) $$ Flame Graph
entity_by_property depths: DT=0, PT=0, ET=0, E=0 $$38.9 \mathrm{ms} \pm 263 \mathrm{μs}\left({\color{lightgreen}-6.315 \mathrm{\%}}\right) $$ Flame Graph
entity_by_property depths: DT=2, PT=2, ET=2, E=2 $$56.8 \mathrm{ms} \pm 433 \mathrm{μs}\left({\color{lightgreen}-5.325 \mathrm{\%}}\right) $$ Flame Graph
entity_by_property depths: DT=0, PT=0, ET=0, E=2 $$42.7 \mathrm{ms} \pm 298 \mathrm{μs}\left({\color{lightgreen}-5.600 \mathrm{\%}}\right) $$ Flame Graph
entity_by_property depths: DT=0, PT=0, ET=2, E=2 $$48.4 \mathrm{ms} \pm 300 \mathrm{μs}\left({\color{gray}-4.732 \mathrm{\%}}\right) $$ Flame Graph
entity_by_property depths: DT=0, PT=2, ET=2, E=2 $$53.4 \mathrm{ms} \pm 330 \mathrm{μs}\left({\color{gray}-3.878 \mathrm{\%}}\right) $$ Flame Graph
link_by_source_by_property depths: DT=255, PT=255, ET=255, E=255 $$108 \mathrm{ms} \pm 558 \mathrm{μs}\left({\color{gray}-4.406 \mathrm{\%}}\right) $$ Flame Graph
link_by_source_by_property depths: DT=0, PT=0, ET=0, E=0 $$42.5 \mathrm{ms} \pm 289 \mathrm{μs}\left({\color{lightgreen}-5.491 \mathrm{\%}}\right) $$ Flame Graph
link_by_source_by_property depths: DT=2, PT=2, ET=2, E=2 $$99.6 \mathrm{ms} \pm 799 \mathrm{μs}\left({\color{gray}-3.892 \mathrm{\%}}\right) $$ Flame Graph
link_by_source_by_property depths: DT=0, PT=0, ET=0, E=2 $$81.7 \mathrm{ms} \pm 453 \mathrm{μs}\left({\color{gray}-4.787 \mathrm{\%}}\right) $$ Flame Graph
link_by_source_by_property depths: DT=0, PT=0, ET=2, E=2 $$90.9 \mathrm{ms} \pm 535 \mathrm{μs}\left({\color{gray}-4.498 \mathrm{\%}}\right) $$ Flame Graph
link_by_source_by_property depths: DT=0, PT=2, ET=2, E=2 $$95.4 \mathrm{ms} \pm 479 \mathrm{μs}\left({\color{gray}-4.214 \mathrm{\%}}\right) $$ Flame Graph

representative_read_entity_type

Function Value Mean Flame graphs
get_entity_type_by_id Account ID: d4e16033-c281-4cde-aa35-9085bf2e7579 $$1.42 \mathrm{ms} \pm 6.63 \mathrm{μs}\left({\color{gray}-0.984 \mathrm{\%}}\right) $$ Flame Graph

scaling_read_entity_complete_one_depth

Function Value Mean Flame graphs
entity_by_id 50 entities $$5.32 \mathrm{s} \pm 850 \mathrm{ms}\left({\color{gray}-2.967 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 5 entities $$27.6 \mathrm{ms} \pm 158 \mathrm{μs}\left({\color{gray}-0.120 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 1 entities $$21.5 \mathrm{ms} \pm 138 \mathrm{μs}\left({\color{gray}0.377 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 10 entities $$59.1 \mathrm{ms} \pm 317 \mathrm{μs}\left({\color{gray}-0.818 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 25 entities $$182 \mathrm{ms} \pm 1.02 \mathrm{ms}\left({\color{gray}-1.194 \mathrm{\%}}\right) $$ Flame Graph

scaling_read_entity_linkless

Function Value Mean Flame graphs
entity_by_id 1 entities $$1.96 \mathrm{ms} \pm 8.56 \mathrm{μs}\left({\color{gray}-2.443 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 100 entities $$2.14 \mathrm{ms} \pm 7.04 \mathrm{μs}\left({\color{gray}-2.073 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 10 entities $$2.00 \mathrm{ms} \pm 8.45 \mathrm{μs}\left({\color{gray}-1.237 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 1000 entities $$2.92 \mathrm{ms} \pm 14.4 \mathrm{μs}\left({\color{gray}-3.445 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 10000 entities $$13.8 \mathrm{ms} \pm 53.0 \mathrm{μs}\left({\color{lightgreen}-6.862 \mathrm{\%}}\right) $$ Flame Graph

scaling_read_entity_complete_zero_depth

Function Value Mean Flame graphs
entity_by_id 50 entities $$5.18 \mathrm{ms} \pm 24.6 \mathrm{μs}\left({\color{red}21.6 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 5 entities $$1.99 \mathrm{ms} \pm 10.5 \mathrm{μs}\left({\color{gray}-2.756 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 1 entities $$1.98 \mathrm{ms} \pm 9.87 \mathrm{μs}\left({\color{gray}-1.491 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 10 entities $$2.19 \mathrm{ms} \pm 8.96 \mathrm{μs}\left({\color{gray}-3.653 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 25 entities $$3.37 \mathrm{ms} \pm 16.2 \mathrm{μs}\left({\color{gray}-3.378 \mathrm{\%}}\right) $$ Flame Graph

Merged via the queue into main with commit d7f2ebd Dec 3, 2024
166 checks passed
@indietyp indietyp deleted the bm/h-3707-typescript-libp2p-implementation branch December 3, 2024 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/deps Relates to third-party dependencies (area) area/libs Relates to first-party libraries/crates/packages (area) area/tests New or updated tests type/eng > backend Owned by the @backend team
Development

Successfully merging this pull request may close these issues.

2 participants