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

Lazy load correlation IDs event sources #70

Open
simontabor opened this issue Jul 4, 2019 · 0 comments
Open

Lazy load correlation IDs event sources #70

simontabor opened this issue Jul 4, 2019 · 0 comments

Comments

@simontabor
Copy link
Contributor

This is a Feature Proposal

Description

  • After Feature/refactor correlation ids #57, we will load up all of the event sources (individual files) on cold-start
  • Most lambda functions will only have a single event source, so only one of these files needs to be loaded
  • As discussed on the PR, we could lazily load the event sources as required.

The implementation could look something like this:

const eventSourceDetector = require('./event-source-detector');
const getEventSource = event => {
  const source = eventSourceDetector(event);
  if (!source) return require('./event-sources/generic');
  return require(`./event-sources/${source}`);
});
// ...
const eventSource = getEventSource(event);
eventSource.captureCorrelationIds(event, context, sampleDebugLogRate);

eventSourceDetector would basically combine the isMatch functions from all the sources in one function, which isn't quite so nice to maintain but would have reasonable cold-start time improvements. require caching is very efficient, so we can rely on that for the lazy-loading.

As this is an optimisation, we need to know whether the change actually has any useful impact on cold-start times before merging any changes.

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

No branches or pull requests

1 participant