30x performance improvement on target.events filter function
See original GitHub issueI 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:
- Created 7 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This sounds interesting @alexanderschana — want to put together a PR?
@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.