Skip to content

perf: remove unneeded arguments copies, break type import cycles and restore TypeScript v3.4 types - #639

Merged
nev21 merged 1 commit into
mainfrom
nev21/Perf
Nov 9, 2026
Merged

nev21 merged 1 commit into
mainfrom
nev21/Perf

Conversation

@nev21

@nev21 nev21 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Performance

  • arrSlice now uses _unwrapFunction("slice", ArrProto) rather than slicing its own arguments before calling slice (~16% faster in a V8 micro-benchmark and smaller). It still uses the value's own slice when present, but as it is now a const its name and length change
  • createFnDeferredProxy, objExtend, deepExtend, the createCustomError base class call and the timer callback wrapper now pass their arguments object directly rather than copying it (objExtend ~29% faster). ES5 is the minimum runtime and every call has its own arguments object
  • The arguments are still copied where they are kept or modified after the call returns (_createTimeoutWith and scheduleInterval for refresh()), with comments explaining why

Cyclic dependencies

  • Move ICachedValue, ILazyValue, TimeoutOverrideFn, ClearTimeoutOverrideFn and TimeoutOverrideFuncs to helpers/types.ts, which has no imports, and re-export them from their original modules. This removes the type-level import cycle between cache, lazy, define, global, handler and timeout, without using import type (TypeScript v3.8)

Exported types now compile with TypeScript v3.4, as documented

  • Add helpers/deep_types.ts: DeepPartial, DeepReadonly and DeepRequired now resolve arrays through new DeepPartialArray, DeepReadonlyArray and DeepRequiredArray interfaces, as a type alias can't reference itself as a type argument before v3.7. The resulting types are unchanged
  • ObjDefinePropDescriptorMap is now Record<PropertyKey, ...>
  • Add library-owned types for lib types that older compilers or an ES2015 lib don't provide:
    • IAsyncGeneratorFunction, used by isAsyncGenerator
    • IAsyncIterable and IAsyncIterator, used by isAsyncIterable. On TypeScript v4.3+ these are interchangeable with the native types. Older compilers using the ES2018 lib see any, so a value declared as a union with AsyncIterable is no longer narrowed on those versions
    • IIdleDeadline, IIdleRequestOptions and IdleCallbackFn, used by RequestIdleCallback and scheduleIdleCallback

@nev21 nev21 added this to the 0.20.0 milestone Nov 9, 2026
@nev21
nev21 requested review from a team as code owners November 9, 2026 03:22
Copilot AI balanced review requested due to automatic review settings November 9, 2026 03:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@codecov

codecov Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.22%. Comparing base (c76f017) to head (f5877c7).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #639   +/-   ##
=======================================
  Coverage   99.21%   99.22%           
=======================================
  Files         180      181    +1     
  Lines        5630     5688   +58     
  Branches     1297     1287   -10     
=======================================
+ Hits         5586     5644   +58     
  Misses         44       44           
Files with missing lines Coverage Δ
lib/src/array/arrIndexOfSubset.ts 100.00% <ø> (ø)
lib/src/array/slice.ts 100.00% <100.00%> (ø)
lib/src/funcs/fnProxy.ts 100.00% <100.00%> (ø)
lib/src/helpers/base.ts 100.00% <100.00%> (ø)
lib/src/helpers/cache.ts 100.00% <100.00%> (ø)
lib/src/helpers/customError.ts 100.00% <100.00%> (ø)
lib/src/helpers/deep_types.ts 100.00% <100.00%> (ø)
lib/src/helpers/extend.ts 100.00% <100.00%> (ø)
lib/src/helpers/lazy.ts 100.00% <100.00%> (ø)
lib/src/helpers/types.ts 100.00% <ø> (ø)
... and 7 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A critical active finding remains because the common test suite references the ES2018-only AsyncGeneratorFunction type while compiling against ES2015 libraries, causing test compilation to fail before execution.

1 open issue

Review effort: Lite

nevware21-bot
nevware21-bot previously approved these changes Nov 9, 2026

@nevware21-bot nevware21-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved by nevware21-bot

…restore TypeScript v3.4 types

Performance
- arrSlice now uses _unwrapFunction("slice", ArrProto) rather than slicing  its own arguments before calling slice (~16% faster in a V8 micro-benchmark and smaller). It still uses the value's own slice when present, but as it is now a const its name and length change
- createFnDeferredProxy, objExtend, deepExtend, the createCustomError base  class call and the timer callback wrapper now pass their arguments object  directly rather than copying it (objExtend ~29% faster). ES5 is the minimum  runtime and every call has its own arguments object
- The arguments are still copied where they are kept or modified after the  call returns (_createTimeoutWith and scheduleInterval for refresh()), with  comments explaining why

Cyclic dependencies
- Move ICachedValue, ILazyValue, TimeoutOverrideFn, ClearTimeoutOverrideFn and TimeoutOverrideFuncs to helpers/types.ts, which has no imports, and re-export them from their original modules. This removes the type-level import cycle between cache, lazy, define, global, handler and timeout, without using import type (TypeScript v3.8)

Exported types now compile with TypeScript v3.4, as documented
- Add helpers/deep_types.ts: DeepPartial, DeepReadonly and DeepRequired now resolve arrays through new DeepPartialArray, DeepReadonlyArray and DeepRequiredArray interfaces, as a type alias can't reference itself as a type argument before v3.7. The resulting types are unchanged
- ObjDefinePropDescriptorMap is now Record<PropertyKey, ...>
- Add library-owned types for lib types that older compilers or an ES2015 lib don't provide:
  - IAsyncGeneratorFunction, used by isAsyncGenerator
  - IAsyncIterable and IAsyncIterator, used by isAsyncIterable. On TypeScript v4.3+ these are interchangeable with the native types. Older compilers using the ES2018 lib see any, so a value declared as a union with AsyncIterable is no longer narrowed on those versions
  - IIdleDeadline, IIdleRequestOptions and IdleCallbackFn, used by RequestIdleCallback and scheduleIdleCallback
Copilot AI lite review requested due to automatic review settings November 9, 2026 04:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The changes span public declarations and runtime wrappers across multiple TypeScript versions, library targets, and browser/worker environments, requiring compatibility validation beyond the available snapshot checks.

1 open issue

Review effort: Lite

@nevware21-bot nevware21-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved by nevware21-bot

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Defer because the compatibility change requires validating declarations, assignability, and API-extractor output across the supported TypeScript and library-version matrix, which this review snapshot cannot verify.

No open issues 🎉

1 resolved since last review

Review effort: Lite

@nev21
nev21 merged commit 69209cc into main Nov 9, 2026
17 checks passed
@nev21
nev21 deleted the nev21/Perf branch November 9, 2026 06:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants