duckduckgo / duckduckgo/content-scope-scripts
Overloaded constructor of Date is slow
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 70
- Forks
- 35
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 40
Description
With the overloaded Date constructor, creating new Date objects takes at least an order of magnitude longer on Firefox, blocking the main JS thread and causing performance issues on sites that process large number of dates.
This is largely due to the new URL(...) constructor being called multiple times to extract origin of each script on the stack during the new Date call, to check if Date hasTaintedMethod. The URL constructor is much slower than the Date constructor (about ~ 9x times slower).
I'm not sure why such check for tainted methods on Date object is important, but I would suggest to at least check if taintedOrigins is not-empty before doing https://github.com/duckduckgo/content-scope-scripts/blob/aff1438cca2cd1702bc80f623679ce6b6ba9406e/src/utils.js#L392 to improve performance.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/utils.js around line 392 and trace the overloaded Date constructor path that checks tainted methods and extracts script origins. Confirm the relevant behavior remains intact while addressing the repeated URL-construction cost; done means the Date path no longer incurs that unnecessary overhead.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- performance
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100