Variable Shadowing for JavaScript Code Compression

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Existing source code compression methods fail to effectively reduce the size of JavaScript programs with nested functions, leading to increased latency and bandwidth costs during transmission.

Innovation Solution

The method involves identifying upward referencing variable names in source programs with nested functions, renaming candidate shadow variables to minimize bandwidth usage by compressing the code, and transmitting the compressed program over networks.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Loss of information

If variable names are kept unique and explicit in nested functions, then code readability and correctness are maintained, but code size increases and compression efficiency decreases

Engineering Contradiction:
Improvecode sizeVSAvoidcode readability
Core Design Contradiction:
Loss of informationVSEase of operation

Solution Approach 1:

The patent applies local quality by allowing variable name shadowing only in specific local scopes (inner functions) where it is safe to do so, while maintaining unique names in outer scopes. The system analyzes the scope hierarchy and selectively renames variables in inner functions to match outer function variable names when no upward references exist, thereby reducing code size locally without affecting global code correctness or readability.

Inventive Principle:
Principle #3Local quality

Solution Approach 2:

The patent changes the parameter of variable naming from 'unique names throughout' to 'context-dependent names'. By analyzing upward references and scope relationships, the system dynamically determines whether to use shadowing (same name) or maintain uniqueness (different name) based on the local context, optimizing compression while preserving correctness.

Inventive Principle:
Principle #35Parameter changes

2Loss of time

If compression algorithms are applied to reduce JavaScript size, then bandwidth costs and latency are reduced, but the complexity of code transformation increases

Engineering Contradiction:
Improvetransmission latencyVSAvoidcode transformation complexity
Core Design Contradiction:
Loss of timeVSDevice complexity

Solution Approach 1:

The patent performs preliminary action by pre-analyzing the code structure, identifying upward references, and determining safe shadowing opportunities before compression. This upfront analysis creates a transformation map that guides the renaming process, making the overall transformation simpler and more systematic rather than attempting complex compression directly.

Inventive Principle:
Principle #10Preliminary action

Solution Approach 2:

The patent introduces an intermediary analysis phase that sits between the original code and the compression algorithm. This intermediary step identifies safe renaming opportunities and prepares the code structure, acting as a mediator that simplifies the subsequent compression process and avoids the need for complex direct compression of nested function scopes.

Inventive Principle:
Principle #24Intermediary (Mediator)

3Quantity of substance

If variable shadowing is applied to reduce code size, then bandwidth requirements are reduced, but the risk of introducing naming conflicts increases

Engineering Contradiction:
Improvebandwidth usageVSAvoidnaming conflict avoidance
Core Design Contradiction:
Quantity of substanceVSReliability

Solution Approach 1:

The patent employs feedback by analyzing upward references to determine whether a variable name can be safely shadowed. The system checks if inner function variables reference outer scope variables, and only allows shadowing when no such references exist. This feedback mechanism ensures that shadowing decisions maintain correctness while achieving compression goals.

Inventive Principle:
Principle #23Feedback

Solution Approach 2:

The patent applies preliminary anti-action by proactively identifying and preventing potential naming conflicts before they occur. By analyzing the scope hierarchy and upward references in advance, the system determines safe shadowing opportunities, thereby preventing naming conflicts before they can affect code correctness or execution.

Inventive Principle:
Principle #9Preliminary anti-action

Data Source

PatentUS8893099B1Inner function local variable name shadowing
Publication Date: 2014.11.18 GOOGLE LLC
  • US8893099B1 patent drawing
  • US8893099B1 patent drawing
  • US8893099B1 patent drawing

AI summary

A system of one or more processors, method, and computer readable storage medium, by which a source program having at least one inner scope is processed by identifying variable names in the source program that are upward referencing and storing the upward referencing variable names with an identifier for the associated scope. A candidate shadow variable in a current scope of the source program is determined from variable names that are not among the identified upward referencing variable names. The determined candidate shadow variable is renamed to a variable name that is in an outer scope relative to the current scope. The source program is stored with the renamed variable. The stored source program can be compressed to a size smaller than the original source program in order to require less bandwidth during transmission over a network.