From 02f2ee98787997cc53ba448d7d305da88b6adb7a Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 11 Feb 2026 19:13:08 +0000 Subject: [PATCH 1/2] Refactor BackgroundService to use Date.now() instead of moment() for timestamps Co-authored-by: xRahul <1639945+xRahul@users.noreply.github.com> --- scripts/benchmark_moment.js | 25 +++++++++++++++++++++++++ src/services/BackgroundService.js | 5 +---- 2 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 scripts/benchmark_moment.js diff --git a/scripts/benchmark_moment.js b/scripts/benchmark_moment.js new file mode 100644 index 0000000..a46bc55 --- /dev/null +++ b/scripts/benchmark_moment.js @@ -0,0 +1,25 @@ +const moment = require('moment'); + +const ITERATIONS = 1000000; + +console.log(`Running benchmark with ${ITERATIONS} iterations...`); + +// Benchmark Moment.js +const startMoment = process.hrtime(); +for (let i = 0; i < ITERATIONS; i++) { + moment().valueOf().toString(); +} +const endMoment = process.hrtime(startMoment); +const timeMoment = endMoment[0] * 1000 + endMoment[1] / 1000000; + +// Benchmark Date.now() +const startDate = process.hrtime(); +for (let i = 0; i < ITERATIONS; i++) { + Date.now().toString(); +} +const endDate = process.hrtime(startDate); +const timeDate = endDate[0] * 1000 + endDate[1] / 1000000; + +console.log(`Moment.js: ${timeMoment.toFixed(2)}ms`); +console.log(`Date.now(): ${timeDate.toFixed(2)}ms`); +console.log(`Improvement: ${(timeMoment / timeDate).toFixed(2)}x faster`); diff --git a/src/services/BackgroundService.js b/src/services/BackgroundService.js index f88d78d..1192a92 100644 --- a/src/services/BackgroundService.js +++ b/src/services/BackgroundService.js @@ -1,7 +1,6 @@ import AsyncStorage from '@react-native-community/async-storage'; import BackgroundTimer from 'react-native-background-timer'; import PushNotification from 'react-native-push-notification'; -import moment from 'moment'; import {USER_AGENT_DESKTOP, WEB_PLATFORM_DESKTOP} from '../Constants'; import {escapeRegExp} from '../Utils'; @@ -57,9 +56,7 @@ export const checkUrlForText = async checkUrlForTextData => { await AsyncStorage.setItem( 'lastChecked', - moment() - .valueOf() - .toString(), + Date.now().toString(), ); } catch (error) { console.log(error); From 5b73e7e09aecb958ec6b066040aab636d49c2ad8 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 11 Feb 2026 19:15:18 +0000 Subject: [PATCH 2/2] Fix linting issues in BackgroundService.js and benchmark_moment.js Co-authored-by: xRahul <1639945+xRahul@users.noreply.github.com> --- scripts/benchmark_moment.js | 4 +++- src/services/BackgroundService.js | 5 +---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/scripts/benchmark_moment.js b/scripts/benchmark_moment.js index a46bc55..11c4428 100644 --- a/scripts/benchmark_moment.js +++ b/scripts/benchmark_moment.js @@ -7,7 +7,9 @@ console.log(`Running benchmark with ${ITERATIONS} iterations...`); // Benchmark Moment.js const startMoment = process.hrtime(); for (let i = 0; i < ITERATIONS; i++) { - moment().valueOf().toString(); + moment() + .valueOf() + .toString(); } const endMoment = process.hrtime(startMoment); const timeMoment = endMoment[0] * 1000 + endMoment[1] / 1000000; diff --git a/src/services/BackgroundService.js b/src/services/BackgroundService.js index 1192a92..0db92a1 100644 --- a/src/services/BackgroundService.js +++ b/src/services/BackgroundService.js @@ -54,10 +54,7 @@ export const checkUrlForText = async checkUrlForTextData => { }); } - await AsyncStorage.setItem( - 'lastChecked', - Date.now().toString(), - ); + await AsyncStorage.setItem('lastChecked', Date.now().toString()); } catch (error) { console.log(error); }