Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

require-atomic-updates takes a very long time to run on large files #10893

Closed
reintroducing opened this issue Sep 25, 2018 · 3 comments
Closed
Assignees
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly rule Relates to ESLint's core rules

Comments

@reintroducing
Copy link

Tell us about your environment

  • ESLint Version: 5.6 (though issue starts at 5.3)
  • Node Version: 10.3.0
  • npm Version: 6.1.0

What parser (default, Babel-ESLint, etc.) are you using?
babel-eslint

Please show your full configuration:

Configuration
{
    "extends": "@spothero",
    "settings": {
        "react": {
            "version": "latest"
        }
    },
    "rules": {
        "require-atomic-updates": 2
    }
}

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

import includes from 'lodash/includes';
import moment from 'moment';
import APIUtils from '@spothero/utils/api';
import StorageUtils from '@spothero/utils/storage';
import Config from 'config';
import UserUtils from 'user/user-utils';
import SearchTracking from 'utils/search-tracking';
import SegmentUtils from 'utils/segment';

const ReservationAPI = {
    async add({
        checkoutData,
        selectedRate,
        monthlyStarts = null,
        facility,
        onError,
        stripeToken = false,
        stripePaymentType = 'cc',
        setNewCardAsDefault = false,
        onSuccess = null,
        includeVehicleInResponse = false,
        includeFacilityInResponse = false,
        source = null,
        rentalSourceReferrer = null,
        checkoutStartTime = null
    }) {
        const {
            user,
            promoCode,
            isMonthly,
            eventId,
            paymentRequired,
            purchaseForCustomer,
            purchaseForCustomerReferralSource,
            purchaseForCustomerDescription,
            purchaseOnBehalfOfCustomer,
            affiliate,
            phoneNumberRequired,
            selectedCreditCard,
            licensePlateRequired,
            selectedLicensePlate,
            licensePlateState,
            newLicensePlate,
            newLicensePlateName,
            newLicensePlateIsDefault,
            referralSource,
            smsParkingPass,
            forceRedundantMonthly,
            vehicleMake,
            vehicleModel,
            vehicleYear,
            vehicleColor,
            saveVehicleAsDefault,
            acceptedTerms,
            contractFullName
        } = checkoutData;
        const ratePrice = (selectedRate.price / 100);
        const phoneNumberCleaned = (user.phoneNumber) ? user.phoneNumber.replace(/\D/g, '') : null;
        const isUserSavingNewCard = (user.status === UserUtils.AUTH_STATE.USER && selectedCreditCard === 'new' && !purchaseForCustomer && paymentRequired);
        const isMonthlyRecurringNewCard = (selectedCreditCard === 'new' && isMonthly && selectedRate.recurrable);
        const isPaymentRequired = (selectedCreditCard === 'admin') ? false : paymentRequired;
        const {
            searchUUID,
            actionUUID
        } = SearchTracking.getValues();
        const postData = {
            email: user.email,
            price: parseInt(Math.round(Number(ratePrice) * 100), 10),
            facility: facility.parking_spot_id,
            apply_sh_credit: (user.status === UserUtils.AUTH_STATE.USER),
            search_id: searchUUID,
            action_id: actionUUID
        };
        const config = {};
        const shExperimentVariations = StorageUtils.get('sh-experiment-variations', 'cookie');

        if (includeFacilityInResponse) {
            postData.include = 'facility';
        }

        if (includeVehicleInResponse) {
            if (postData.include) {
                postData.include += ',vehicle_info';
            } else {
                postData.include = 'vehicle_info';
            }
        }

        if (isMonthly) {
            postData.monthly_start_date = moment(monthlyStarts).format(Config.apiDateFormat);
            postData.rule = selectedRate.fullRule;
        } else {
            postData.starts = selectedRate.starts;
            postData.ends = selectedRate.ends;
            postData.rule_group_id = selectedRate.rule_group_id;
        }

        if (eventId) {
            postData.event = eventId;
        }

        if (user.phoneNumber && !phoneNumberCleaned) {
            postData.phone_number = user.phoneNumber;
        } else {
            if (phoneNumberCleaned) {
                postData.phone_number = phoneNumberCleaned;
            }
        }
    },
};

export default ReservationAPI;
eslint test.js

What did you expect to happen?
ESLint runs quickly on that file and shows all errors.

What actually happened? Please include the actual, raw output from ESLint.
The expected behavior happened, however it took WAY longer than it should have on this file. The file is contrived, its just a part of a file in our codebase where I started to see issues when I started to drill down into this. We just upgraded from ESLint 5.2 to 5.6 on a large codebase and ESLint was stalling. We use our own config (https://github.com/spothero/eslint-config) so I naturally thought it was something I had messed up in the config.

I then created a repo that just had the test.js file and the above .eslintrc file. Through editing various things, I was finally able to realize that the require-atomic-updates rule was the culprit. If you disable it in the config with 0, the file executes quickly. If you enable it, the file takes MUCH longer to execute. This becomes magnified when you have many files in the codebase and ESLint just seems to hang without ever finishing them and moving on to the next build step.

@eslint-deprecated eslint-deprecated bot added the triage An ESLint team member will look at this issue soon label Sep 25, 2018
@not-an-aardvark
Copy link
Member

not-an-aardvark commented Sep 25, 2018

Hi, thanks for the report. I can reproduce this issue. My guess is that the require-atomic-updates rule is inadvertently doing an exponential-time graph traversal, so it's particularly slow on functions that have a lot of conditional branches.

@not-an-aardvark not-an-aardvark added bug ESLint is working incorrectly rule Relates to ESLint's core rules accepted There is consensus among the team that this change meets the criteria for inclusion and removed triage An ESLint team member will look at this issue soon labels Sep 25, 2018
@not-an-aardvark not-an-aardvark changed the title require-atomic-updates breaking ESLint in large codebase require-atomic-updates takes a very long time to run on large files Sep 25, 2018
@not-an-aardvark not-an-aardvark self-assigned this Sep 25, 2018
@reintroducing
Copy link
Author

thanks @not-an-aardvark!

@reintroducing
Copy link
Author

sorry meant to add that you are probably correct in the conditional branches part because the moment i started to remove more and more of the if statements (also my original code has alot more than that) and go down to only one, it is much faster (but still not as quick as I'd expect).

not-an-aardvark added a commit that referenced this issue Sep 26, 2018
Previously, the `no-atomic-updates` rule would traverse over every path in the control flow graph, resulting in a runtime that was exponential in the number of edges in the graph. This commit updates the rule to use a lattice-based [dataflow analysis](https://en.wikipedia.org/wiki/Data-flow_analysis) algorithm, similar to the algorithms used by optimizing compilers.
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Mar 28, 2019
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Mar 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly rule Relates to ESLint's core rules
Projects
None yet
Development

No branches or pull requests

2 participants