Skip to content

[HOLD for payment 2023-10-30] parseISO from date-fns is pretty slow, we can replace parseISO from date-fns with Date() #29271

Closed

Description

@muttmuure

Problem:

date-fns is a great library but it’s underperforming in some scenarios For example, using parseISO function takes around 112 ms and it’s a lot of time for a utility function. The main problem we have at our hands is most of the work is already been done in moving from moment to date-fns . While date-fns is a good library and works well in other scenarios, which otherwise haven’t been reported by profiler but parseISO is such a utility function which is consuming noticeable milliseconds and reported by profiler.

Solution:

We have two solutions here:

Given our efforts in migrating from moment to date-fns , we can use stock new Date(dateToParse) in place of parseISO and it works really well. Looking at the benchmarks, parseISO can perform around 69-71k operations per second, whereas new Date can perform around 379k operations per second.

We can introduce dayjs which we can use in place of parseISO and in rest of the places we can still use date-fns unless in future if Profiler states to us that this certain function is slow, so we can gradually replace date-fns from the codebase. In our codebase, we are using this parseISO function in only a couple of places and we can easily refactor the codebase. A good alternative to date-fns is dayjs and it’s also a lighter one, only 2KB in size. Using dayjs in place of parseISO function, we see that it takes around 23 ms in Profiler. Also, if we take a closer look at the comparisons benchmarks, parseISO can perform around 69-71k operations per second, whereas dayjs can perform around 167k operations per second, which is a lot of difference.

Since we have spent a lot of efforts in migrating from moment to date-fns and certainly it’s better than moment but in some scenarios, some utility functions of date-fns are underperforming. Ideally, we can replace those underperforming parts with new Date and in future, if there are any other underperforming utility functions reported by Profiler, we can decide whether it’s fixable by using stock Date or now it is time to gradually adopt dayjs or any other efficient date library.

Activity

  1. self-assigned this
    on Oct 11, 2023
  2. mountiny commented on Oct 11, 2023

    @mountiny
    Contributor

    @waterim @hurali97 would you like to comment on this issue so we can assign you?

  3. waterim commented on Oct 11, 2023

    @waterim
    Contributor

    Hey, Im Artem from Callstack and would like to help with this one

  4. waterim commented on Oct 12, 2023

    @waterim
    Contributor

    Hey @mountiny, this PR is ready for review

  5. 2 remaining items

  6. changed the title [-]parseISO from date-fns is pretty slow, we can replace parseISO from date-fns with Date()[/-] [+][HOLD for payment 2023-10-30] parseISO from date-fns is pretty slow, we can replace parseISO from date-fns with Date()[/+] on Oct 23, 2023
  7. melvin-bot commented on Oct 23, 2023

    @melvin-bot

    Reviewing label has been removed, please complete the "BugZero Checklist".

  8. melvin-bot commented on Oct 23, 2023

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 1.3.88-11 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

    If no regressions arise, payment will be issued on 2023-10-30. 🎊

    After the hold period is over and BZ checklist items are completed, please complete any of the applicable payments for this issue, and check them off once done.

    • External issue reporter
    • Contributor that fixed the issue
    • Contributor+ that helped on the issue and/or PR

    For reference, here are some details about the assignees on this issue:

    • @waterim does not require payment (Contractor)

    As a reminder, here are the bonuses/penalties that should be applied for any External issue:

    • Merged PR within 3 business days of assignment - 50% bonus
    • Merged PR more than 9 business days after assignment - 50% penalty
  9. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Oct 24, 2023
  10. melvin-bot commented on Oct 24, 2023

    @melvin-bot

    Triggered auto assignment to @isabelastisser (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

  11. melvin-bot commented on Oct 24, 2023

    @melvin-bot

    Bug0 Triage Checklist (Main S/O)

    • This "bug" occurs on a supported platform (ensure Platforms in OP are ✅)
    • This bug is not a duplicate report (check E/App issues and #expensify-bugs)
      • If it is, comment with a link to the original report, close the issue and add any novel details to the original issue instead
    • This bug is reproducible using the reproduction steps in the OP. S/O
      • If the reproduction steps are clear and you're unable to reproduce the bug, check with the reporter and QA first, then close the issue.
      • If the reproduction steps aren't clear and you determine the correct steps, please update the OP.
    • This issue is filled out as thoroughly and clearly as possible
      • Pay special attention to the title, results, platforms where the bug occurs, and if the bug happens on staging/production.
    • I have reviewed and subscribed to the linked Slack conversation to ensure Slack/Github stay in sync
  12. mountiny commented on Oct 24, 2023

    @mountiny
    Contributor

    this is ready to pay $500 to @fedirjh for their review and testing! @isabelastisser thank you!

  13. isabelastisser commented on Oct 25, 2023

    @isabelastisser
    Contributor

    Hey @fedirjh, I sent you the offer in Upwork. Please accept it, and I will process the payment ASAP. Thanks!

    All set, closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2Engineering

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions