perf(lambda): drop the base64 encode->decode round-trip on the S3 code path (#1666)

extractZipCodeFromS3 (and the S3 code-update path) base64-encoded the fetched
object bytes only for extractZipCode to immediately base64-decode them back,
burning CPU + allocating a String ~1.33x the (often tens-of-MB) zip on every
create/update. Split out extractZipCodeBytes(fn, byte[]) as the core and make
extractZipCode(fn, base64) a decode-and-delegate shim; the S3 paths now hand the
bytes straight through. Behavior-identical (decode(encode(x)) == x); covered by
the existing Lambda code tests.
This commit is contained in:
Alex Banna authored and GitHub committed 2026-07-03 01:04:18 -05:00
1 parent a8d25525d7
commit 44298a2755
1 file changed
+6 -3
@@ -1135,7 +1135,10 @@ public class LambdaService {
}
private void extractZipCode(LambdaFunction fn, String zipFileBase64) {
byte[] zipBytes = Base64.getDecoder().decode(zipFileBase64);
extractZipCodeBytes(fn, Base64.getDecoder().decode(zipFileBase64));
}
private void extractZipCodeBytes(LambdaFunction fn, byte[] zipBytes) {
Path codePath = codeStore.getCodePath(fn.getFunctionName());
try {
zipExtractor.extractTo(zipBytes, codePath);
@@ -1191,7 +1194,7 @@ public class LambdaService {
throw new AwsException("InvalidParameterValueException",
"Unable to fetch code from s3://" + s3Bucket + "/" + s3Key + ": " + e.getMessage(), 400);
}
extractZipCode(fn, Base64.getEncoder().encodeToString(obj.getData()));
extractZipCodeBytes(fn, obj.getData());
}
private String resolveHandlerFilePath(LambdaFunction fn) {
@@ -1482,7 +1485,7 @@ public class LambdaService {
fn.getFunctionName(), event.bucketName(), event.key());
try {
S3Object obj = s3Service.getObject(event.bucketName(), event.key());
extractZipCode(fn, Base64.getEncoder().encodeToString(obj.getData()));
extractZipCodeBytes(fn, obj.getData());
fn.setLastModified(Instant.now().toEpochMilli());
fn.setRevisionId(UUID.randomUUID().toString());
functionStore.save(region, fn);