Skip to content

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.

2 participants