Apex Bytecode Caching for Multi-Tenant Performance

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

In multi-tenant database systems, the high start-up costs associated with interpreting Apex code in a shared environment lead to performance issues and increased load on the system, as each tenant's code requires significant processor cycles, affecting response times and resource utilization.

Innovation Solution

The implementation of bytecode interpretation, which includes caching executable code using memcached and optimizing bytecode generation to reduce start-up costs, along with delegating to a real Java virtual machine for services like garbage collection, and using stack windows and structs to enhance locality and reduce memory garbage.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Adaptability or versatility

If Apex code is interpreted in a shared multi-tenant environment, then code execution flexibility and multi-tenant support are improved, but start-up costs and processor cycle consumption increase significantly

Engineering Contradiction:
Improvemulti-tenant supportVSAvoidprocessor cycle consumption
Core Design Contradiction:
Adaptability or versatilityVSUse of energy by moving object

Solution Approach 1:

The system performs preliminary compilation of Apex code into bytecode before execution. The bytecode compiler translates Apex source code into intermediate bytecode representation that can be cached and reused across multiple tenants, avoiding repeated interpretation overhead and reducing processor cycle consumption during code execution

Inventive Principle:
Principle #10Preliminary action

Solution Approach 2:

The system creates and caches bytecode copies of compiled Apex code in memory. These bytecode representations serve as reusable intermediates that can be shared across multiple tenants, eliminating the need to re-interpret the same Apex code repeatedly and significantly reducing start-up costs

Inventive Principle:
Principle #26Copying

2Reliability

If Apex code is interpreted for each tenant request, then code execution accuracy is maintained, but response times deteriorate due to high start-up costs

Engineering Contradiction:
Improvecode execution accuracyVSAvoidresponse time
Core Design Contradiction:
ReliabilityVSLoss of time

Solution Approach 1:

The bytecode compiler performs preliminary translation of Apex code into bytecode representation before runtime execution. This pre-compilation step ensures code accuracy is validated during compilation while the cached bytecode enables fast execution without repeated interpretation overhead, thus maintaining reliability while reducing response time

Inventive Principle:
Principle #10Preliminary action

Solution Approach 2:

The system dynamically manages bytecode caching, storing compiled bytecode in memory for rapid retrieval and execution. This dynamic approach allows the system to switch from expensive interpretation to efficient bytecode execution based on code identity, maintaining accuracy while significantly improving response times for repeated tenant requests

Inventive Principle:
Principle #15Dynamics

3Productivity

If a shared environment is used for multiple tenants, then resource utilization efficiency is improved, but the impact of one tenant's code execution on others increases

Engineering Contradiction:
Improveresource utilization efficiencyVSAvoidinter-tenant interference
Core Design Contradiction:
ProductivityVSObject-generated harmful factors

Solution Approach 1:

The system segments code execution into distinct bytecode interpretation sessions for each tenant. By compiling Apex code into tenant-specific bytecode representations and managing separate execution contexts, the system allows efficient shared resource utilization while isolating tenants from each other's code execution impacts

Inventive Principle:
Principle #1Segmentation

Solution Approach 2:

The system creates isolated bytecode copies for each tenant's code execution context. These cached bytecode representations enable efficient shared environment execution while ensuring that one tenant's code operations do not interfere with others, as each tenant operates on its own bytecode instance in a controlled execution environment

Inventive Principle:
Principle #26Copying

Data Source

PatentUS10452363B2Methods and systems for evaluating bytecode in an on-demand service environment including translation of apex to bytecode
Publication Date: 2019.10.22 SALESFORCE INC
  • US10452363B2 patent drawing
  • US10452363B2 patent drawing
  • US10452363B2 patent drawing

AI summary

Techniques and mechanisms for conversion of code of a first type to bytecode. Apex provides various unique characteristics. When converting to bytecode, these characteristics are handled to provide bytecode functionality. Some of the unique characteristics of Apex include Autoboxing, SOQL, Properties, Comparisons, Modifiers, Code coverage mechanisms and Sharing mechanisms.