Skip to content

Discrepancy between lodash and compat throttle with both trailing and leading disabled #1494

@DominikSerafin

Description

@DominikSerafin

While I was sanity-checking the reproduction on this issue, I've found that there's a discrepancy between lodash and compat throttle:

import lodashThrottle from 'lodash-es/throttle';
import compatThrottle from 'es-toolkit/compat/throttle';

const WAIT = 100;
const OPTIONS = {leading: false, trailing: false};

const lodashThrottled = lodashThrottle(() => console.log('lodashThrottled'), WAIT, OPTIONS);
const compatThrottled = compatThrottle(() => console.log('compatThrottled'), WAIT, OPTIONS);

// These seem to be mostly consistent on my machine
setInterval(lodashThrottled, 1);
setInterval(compatThrottled, 1);

// Things start to get inconsistent
setInterval(lodashThrottled, 100);
setInterval(compatThrottled, 100);

// Lodash now executes far more rarely, while compat seems to execute according to delay
// The lodash timing appears to grow exponentially compared to compat
setInterval(lodashThrottled, 115);
setInterval(compatThrottled, 115);

// Note: system/browser workload seems to increase the timing inconsistencies as well

This is a bit extreme edge case considering this seems to happen only with both trailing and leading edges disabled, but configuration like this is still implicitly allowed (even though the effects of doing so are not generally established), so I thought it deserved mention.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions