Skip to content

Optimize scope identifiers transformer performance#1417

Open
filipsobol wants to merge 1 commit into
javascript-obfuscator:masterfrom
filipsobol:master
Open

Optimize scope identifiers transformer performance#1417
filipsobol wants to merge 1 commit into
javascript-obfuscator:masterfrom
filipsobol:master

Conversation

@filipsobol

@filipsobol filipsobol commented Jun 12, 2026

Copy link
Copy Markdown

Summary

Optimize identifier renaming performance for large function scopes.

This code change is AI-generated, but the performance improvement was manually verified with an isolated benchmark.

Details

The slowdown appears when a large bundle is wrapped in a UMD factory function. In that shape, most declarations become local variables of one huge function scope.

The same code in ESM form did not show the issue because top-level declarations remain global and are skipped when renameGlobals is disabled.

The previous implementation could rescan the same lexical scope repeatedly while checking whether var declarations are used by shorthand destructuring assignments. This change caches the relevant destructuring-assignment names per lexical scope, so the scope is scanned once.

No output behavior is intended to change.

Performance

Measured on identical, already-prepared input:

  • ESM before: 7.92s
  • UMD before: 74.51s
  • ESM after: 8.24s
  • UMD after: 7.53s

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.

1 participant