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

chore(sdk): refactor Filter into different modules #1968

Closed
wants to merge 2 commits into from

Conversation

danisharora099
Copy link
Collaborator

@danisharora099 danisharora099 commented Apr 22, 2024

Problem

The current Filter implementation is very tightly coupled together which decreases readability, tough to refactor, and introduce new changes/APIs.

Solution

With work on #1886, we decoupled Filter into core and sdk

This PR splits Filter into:

  • FilterSDK
  • Subscription

@danisharora099 danisharora099 marked this pull request as ready for review April 22, 2024 08:27
@danisharora099 danisharora099 requested a review from a team as a code owner April 22, 2024 08:27
Copy link

github-actions bot commented Apr 22, 2024

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
Waku node 180.8 KB (+0.05% 🔺) 3.7 s (+0.05% 🔺) 20.1 s (-22.12% 🔽) 23.7 s
Waku Simple Light Node 180.8 KB (-0.04% 🔽) 3.7 s (-0.04% 🔽) 25.6 s (+57.49% 🔺) 29.2 s
ECIES encryption 23.11 KB (0%) 463 ms (0%) 4.9 s (+18.38% 🔺) 5.4 s
Symmetric encryption 22.59 KB (0%) 452 ms (0%) 4.8 s (+27.57% 🔺) 5.3 s
DNS discovery 72.42 KB (0%) 1.5 s (0%) 11.6 s (-24.53% 🔽) 13 s
Peer Exchange discovery 73.96 KB (0%) 1.5 s (0%) 18.7 s (+19.23% 🔺) 20.2 s
Local Peer Cache Discovery 67.64 KB (0%) 1.4 s (0%) 11.7 s (-23.84% 🔽) 13.1 s
Privacy preserving protocols 38.87 KB (0%) 778 ms (0%) 9.9 s (+11.5% 🔺) 10.6 s
Waku Filter 111.33 KB (+0.08% 🔺) 2.3 s (+0.08% 🔺) 13.9 s (+9.68% 🔺) 16.1 s
Waku LightPush 110.24 KB (+0.02% 🔺) 2.3 s (+0.02% 🔺) 13.6 s (-28.17% 🔽) 15.8 s
History retrieval protocols 110.89 KB (+0.16% 🔺) 2.3 s (+0.16% 🔺) 18.2 s (+29.59% 🔺) 20.4 s
Deterministic Message Hashing 4.83 KB (0%) 97 ms (0%) 819 ms (+134.96% 🔺) 915 ms

@@ -0,0 +1,57 @@
import { FilterCore } from "@waku/core";
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we gain anything by creating SubscriptionManager entity - considering FilterSDK is essentially a manager for subscriptions from FilterCore.

Overall our implementations are simple enough not to make any new classes.

For now goal is to have Core and SDK decoupled - let's formalize other improvements in separate task stream.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

IMO the current Filter implementation is very tightly coupled and this is a change towards bringing maintainability to the codebase. I believe the Filter implementation is complex enough to be seen as simple currently.

I also anticipate introduction of more logic to SubscriptionManager like resubscription for reliability & abstracting each Subscription object with `PubsubTopic

Do you see any cons to this approach?

Copy link
Collaborator Author

@danisharora099 danisharora099 Apr 22, 2024

Choose a reason for hiding this comment

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

Adding on:

  • FilterSDK is meant to be the interface to interact with the Filter protocol -> new APIs etc would exist here
  • SubscriptionManager is responsible for all Subscription object handling related logic
  • Subscription is responsible for handling a Subscription granularly like ping, unsubscribe etc

IMO this only increases readability and maintainability

Do you disagree? What alternative would you suggest?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I understand that decoupling can be beneficial to readability etc.
The thing I am pointing out is - this PR tries to optimize entity that is 150 lines long, which is not that concerning to any of the points mentioned.

I would suggest not to do these improvements unless they are impactful. For example:

  • implementation is big - more than 500 lines - we can add eslint to control it (but we don't have this kind of files for now);
  • hard to maintain - when covering with unit test or making changes - which also brings us to big file problem;

Overall - I think when improvements are done before bad patterns in the code appear - they only make things harder to maintain. Basic case is - in worst case now someone would need to touch 3 files instead of one.

As action point - we can intro eslint rule to prevent big files from appearing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for your reply!

The thing I am pointing out is - this PR tries to optimize entity that is 150 lines long, which is not that concerning to any of the points mentioned.

The Filter class was ~350+ lines long -- so splitting into Subscription and Filter seems in the right direction. Would you agree? (Thus bringing FilterSDK and Subscription to be ~150 lines)

I guess the introduction of SubscriptionManager specifically is in question -- I agree to your point that 3 files would need to be touched, but personally prefer keeping each class for a Single Responsibility

I'm happy to address the PR to remove SubscriptionManager and maintain subscription handling within the FilterSDK class for now and can revisit this later.

Let me know if that's different from what you propose.

Copy link
Collaborator

Choose a reason for hiding this comment

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

so splitting into Subscription and Filter seems in the right direction

yes, I agree it was a good choice

I'm happy to address the PR to remove SubscriptionManager and maintain subscription handling within the FilterSDK class for now and can revisit this later.

let's do this, let's keep Subscription and Filter classes for now and revisit later

Additionally - we can add eslint to prevent big files from appearing so that it would make us refactor when it is time.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sounds good, thanks!

@danisharora099 danisharora099 deleted the chore/refactor/filter branch April 29, 2024 12:50
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

2 participants