Skip to content

Optimization on bridge routes#196

Open
joaolcorreia wants to merge 1 commit into190-amplitude-sdk-supportfrom
feature/bridge-refactor
Open

Optimization on bridge routes#196
joaolcorreia wants to merge 1 commit into190-amplitude-sdk-supportfrom
feature/bridge-refactor

Conversation

@joaolcorreia
Copy link
Contributor

The goal here is to support multiple bridges with minimal penalty, which this refactor achieves. For performance this also tries the default collector routes first and avoids future changes to core collector files.

collectorService = collectorService
)
val bridgeRoutes = collectorService.bridges.foldRight[Route](reject) { (bridge, acc) =>
bridge.route(ctx) ~ acc
Copy link
Collaborator

Choose a reason for hiding this comment

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

While this looks cleaner, it still composes a chain of Pekko directives that are evaluated left-to-right until one matches. In the worst case, this is still O(n), not O(1). To achieve true O(1) dispatch, we'd need to extract the path parameters and use a Map lookup to select the appropriate bridge, rather than chaining routes.

Copy link
Collaborator

Choose a reason for hiding this comment

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

So we need to maintain something like Map[(String, String), Bridge], with vendor/version pairs listed (we can store those mapping in a config to make it more dynamic)

contentType: Option[ContentType] = None,
spAnonymous: Option[String],
analyticsJsEvent: Option[AnalyticsJsBridge.Event] = None,
amplitudeEvent: Option[AmplitudeBridge.AmplitudeEvent] = None
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just noticed this one. If there will be more bridge types, this won`t look clean if extending. Maybe introduce a generic class or sealed trait for event params, and inherit specific ones. Then use pattern matching to detect and use exact one when reading exact values.

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.

2 participants