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

feat: function generator #36

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

feat: function generator #36

wants to merge 2 commits into from

Conversation

oscb
Copy link

@oscb oscb commented Dec 9, 2022

Refactors the Matcher portion of the tsub code to be able to generate functions, instead of interpreting the string every time.

This reduces the time when the matchers are long lived and execute several times. This is particularly useful for destination filters on mobile SDKs.

Performance Comparison

Before:

  • First eval = 0.91ms
  • 10000x evals = 256ms (0.0256ms p/event)

After:

  • First eval = 0.83ms
  • 10000x evals = 203ms (0.0203ms p/event)

Using this FQL:

["and",
      ["=", "context.library.name", {"value": "analytics.js"}],
      ["contains", "context.page.path", {"value": "academy"}],
      ["or", 
        ["=", "event", { "value": "Course Tapped" }],
        ["=", "event", { "value": "Course Clicked" }]
      ],
      ["=", ["lowercase", "event"], { "value": "course clicked" }],
      ["match", "context.ip", { "value": "108*" }]
    ]

To keep compatibility the matches function executes exactly as before (generating the evaluator and executing it right away) and added a getMatcherFunction to actually return the generated function that the consumer can save for performance.

Future work

  • Add the same reusability to transformers
  • Pre-generate these functions in the store (this might have more impact on dependent packages)

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.

1 participant