question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

30x performance improvement on target.events filter function

See original GitHub issue

I think you can dramatically improve the speed of the filterFn within the buildTargetObject method by using a date intersect check instead of isSameStart, isAfterStart, isSameEnd and isBeforeEnd.

The relevant code is on line 1006. On an events list of 3000, the current code completes the filter in around 130ms vs the intersect code at around 4ms. I might’ve missed something, but so far in testing it works 100%.

Current code:

var filterFn = function () {
    var isSameStart = target.date.isSame(
        this._clndrStartDateObject,
        'day');
    var isAfterStart = target.date.isAfter(
        this._clndrStartDateObject,
        'day');
    var isSameEnd = target.date.isSame(
        this._clndrEndDateObject,
        'day');
    var isBeforeEnd = target.date.isBefore(
        this._clndrEndDateObject,
        'day');
    return (isSameStart || isAfterStart)
        && (isSameEnd || isBeforeEnd);
};

Improved code:

var targetEndDate = (target.date) ? target.date.clone().endOf("day") : null;
var filterFn = function () {
    return (this._clndrStartDateObject <= targetEndDate
        && target.date <= this._clndrEndDateObject);
};

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
kylestetzcommented, Jan 19, 2017

This sounds interesting @alexanderschana — want to put together a PR?

0reactions
mikegioiacommented, Nov 27, 2019

@alexalexalex-s Thank you again for your help, this has finally made it’s way into production with #341. I’m going to close this one out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Explore best practices for Spark performance optimization
Filter /Reduce dataSet size. Look for opportunities to filter out data as early as possible in your application pipeline. If there is a...
Read more >
Chapter 18 Filtering (Subsetting) Data | R for HR
Filtering data (i.e., subsetting data) is an important data-management process, as it allows us to: Select or remove a subset of cases from...
Read more >
Relative Date Filter Reference - Salesforce Help
Relative date filters let you filter on date fields using easy-to-understand, human-speech-inspired syntax. For example, instead of filtering on Close Dat.
Read more >
Amazon EventBridge FAQs | Event Bus | Amazon Web Services
An optional filtering step allows only specific source events to flow into the pipe and an optional enrichment step using AWS Lambda, AWS...
Read more >
Create Filters for Columns - Oracle Help Center
A filter limits the results that are displayed when an analysis is run. Together with the columns that you select for the analysis,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found