
Function Memory
The CPU allocation is directly linked to the memory allocation of the function. Java uses CPU disproportionately at startup to compile classes from byte-code to native machine code. This means that if a Lambda function is starved of CPU it will dramatically decrease first invoke latency. If you are unsure of the amount of memory to allocate, start with 2048MB and test values above and below. The open source project aws-lambda-power-tuning can help you visualize and fine-tune the memory configuration of Lambda functions.
JVM Options
You can set JVM configuration using the environment variable JAVA_TOOL_OPTIONS as described in the modifying the runtime environment. For the vast majority of applications you will want to change the default tiered compilation behavior.
JAVA_TOOL_OPTIONS="-XX:+TieredCompilation -XX:TieredStopAtLevel=1"
For an in-depth explanation of tiered compilation, you can read the blog Optimizing AWS Lambda function performance for Java.
This optimization may not be suitable if a Lambda function is running for minutes or is repeating the same piece of code thousands of times within the same execution. An example would be running Monte Carlo simulations.