ParetoStack-cloud 1.4.8: three function samples to judge before installing
Ces pages d’exemples sont en anglais.
The three sample functions ship in the release and use only made-up data. Two gained on the real service, one did not. The product changes a copy of the package; the deployed function is never changed.
Read this first. These functions were written for the product and contain the coding patterns it rewrites. They show what it does, not how much your function will gain. The Lambda figures come from one day, one region, one setting and a few calls, with one copy per version. In a later check the same code on two Lambda instances differed by up to 32 %, so only large ratios mean something in such a run. Release 1.4.8 measures on three copies per version by default; these records predate that.
A separate test of 2026-11-13 on six other functions of ours found no gain of 1.10x or more, and one function became slower.
All samples were written for the product, so they do not predict gains on your code.
In the changes shown below, the names the product generated and its generated comments were edited out and replaced by neutral text (names such as _gen_1). Long generated helper blocks are replaced by a marked line. Nothing else was changed.
How a result is accepted
Original and optimized code answer the same recorded events and the answers must be identical. Release 1.4.8 then calls it a gain only if the optimized code is at least 1.05x faster and faster in every pass; otherwise the package is marked "no gain", "slower" or "inconclusive" and is put aside.
1. Log digest function
gain measured on Lambdaanswers identicalReads batches of application log lines and returns counts, percentiles and error bursts. The sample's local test harness also changes slightly (not shown).
On a narrow screen, scroll the listing sideways: the optimized version is on the right.
| Original: lambda_function.py | Optimized by the product | ||
|---|---|---|---|
| unchanged lines not shown | |||
| 9 | import json | 9 | import json |
| 10 | import re | 10 | import re |
| 11 | 11 | ||
| 12 | [ 50 lines of generated helper code not shown here; they are in the real patch ] | ||
| 62 | |||
| 63 | |||
| 12 | NOISY_SERVICES = ["svc-%04d" % i for i in range(0, 1500, 3)] # health checks, metrics scrapers, the gateway's own pings: not counted | 64 | NOISY_SERVICES = ["svc-%04d" % i for i in range(0, 1500, 3)] # health checks, metrics scrapers, the gateway's own pings: not counted |
| 13 | LEVELS = ["DEBUG", "INFO", "WARN", "ERROR"] | 65 | LEVELS = ["DEBUG", "INFO", "WARN", "ERROR"] |
| 14 | BURST = 3 | 66 | BURST = 3 |
| unchanged lines not shown | |||
| 16 | SLOW_PCT = 25 # ... and how far over it a request may be before it counts as slow | 68 | SLOW_PCT = 25 # ... and how far over it a request may be before it counts as slow |
| 17 | 69 | ||
| 18 | 70 | ||
| 71 | # ---- generated comment (text edited out) ---- | ||
| 72 | try: | ||
| 73 | _gen_1 = re.compile('took (\\d+)ms') | ||
| 74 | except re.error: | ||
| 75 | _gen_1 = None | ||
| 76 | |||
| 77 | |||
| 19 | def parse_lines(lines): | 78 | def parse_lines(lines): |
| 20 | """(timestamp, level, service, message) of every log line; stack-trace lines and blanks are left out.""" | 79 | """(timestamp, level, service, message) of every log line; stack-trace lines and blanks are left out.""" |
| 21 | out = [] | 80 | out = [] |
| 81 | _gen_2 = out.append | ||
| 82 | _gen_3 = len | ||
| 22 | for line in lines: | 83 | for line in lines: |
| 23 | parts = line.split(" ", 3) | 84 | parts = line.split(" ", 3) |
| 24 | if len(parts) == 4 and parts[1] in LEVELS: | 85 | if _gen_3(parts) == 4 and parts[1] in LEVELS: |
| 25 | out.append((parts[0], parts[1], parts[2], parts[3])) | 86 | _gen_2((parts[0], parts[1], parts[2], parts[3])) |
| 26 | return out | 87 | return out |
| 27 | 88 | ||
| 28 | 89 | ||
| 29 | def drop_noise(records): | 90 | def drop_noise(records): |
| 30 | """The records whose service is not on the noise list.""" | 91 | """The records whose service is not on the noise list.""" |
| 31 | kept = [] | 92 | kept = [] |
| 93 | _gen_4 = _gen_5(NOISY_SERVICES) | ||
| 94 | _gen_6 = kept.append | ||
| 32 | for rec in records: | 95 | for rec in records: |
| 33 | if rec[2] in NOISY_SERVICES: | 96 | if (_gen_4(rec[2])): |
| 34 | continue | 97 | continue |
| 35 | kept.append(rec) | 98 | _gen_6(rec) |
| 36 | return kept | 99 | return kept |
| 37 | 100 | ||
| 38 | 101 | ||
| unchanged lines not shown | |||
| 52 | slow = 0 | 115 | slow = 0 |
| 53 | bursts = [] | 116 | bursts = [] |
| 54 | run_service, run_len = None, 0 | 117 | run_service, run_len = None, 0 |
| 118 | _gen_7 = re.compile | ||
| 119 | _gen_8 = int | ||
| 120 | _gen_9 = durations.append | ||
| 121 | _gen_10 = bursts.append | ||
| 122 | _gen_11 = BUDGET_MS * (100 + SLOW_PCT) | ||
| 55 | for ts, level, service, message in records: | 123 | for ts, level, service, message in records: |
| 56 | per_level[level] = per_level.get(level, 0) + 1 | 124 | per_level[level] = per_level.get(level, 0) + 1 |
| 57 | per_service[service] = per_service.get(service, 0) + 1 | 125 | per_service[service] = per_service.get(service, 0) + 1 |
| 58 | took = re.compile(r"took (\d+)ms") | 126 | took = (_gen_1 if _gen_1 is not None else _gen_7(r"took (\d+)ms")) |
| 59 | m = took.search(message) | 127 | m = took.search(message) |
| 60 | if m is not None: | 128 | if m is not None: |
| 61 | ms = int(m.group(1)) | 129 | ms = _gen_8(m.group(1)) |
| 62 | durations.append(ms) | 130 | _gen_9(ms) |
| 63 | if ms > BUDGET_MS * (100 + SLOW_PCT) // 100: | 131 | if ms > _gen_11 // 100: |
| 64 | slow += 1 | 132 | slow += 1 |
| 65 | if level == "ERROR" and service == run_service: | 133 | if level == "ERROR" and service == run_service: |
| 66 | run_len += 1 | 134 | run_len += 1 |
| 67 | if run_len == BURST: | 135 | if run_len == BURST: |
| 68 | bursts.append({"service": service, "at": ts}) | 136 | _gen_10({"service": service, "at": ts}) |
| 69 | else: | 137 | else: |
| 70 | run_service, run_len = (service, 1) if level == "ERROR" else (None, 0) | 138 | run_service, run_len = (service, 1) if level == "ERROR" else (None, 0) |
| 71 | stats = None | 139 | stats = None |
| unchanged lines not shown | |||
| 82 | """SQS batch: {"Records": [{"messageId": ..., "body": "line\\nline\\n..."}, ...]}. Returns an API-style response with one digest per record and the totals.""" | 150 | """SQS batch: {"Records": [{"messageId": ..., "body": "line\\nline\\n..."}, ...]}. Returns an API-style response with one digest per record and the totals.""" |
| 83 | results = [] | 151 | results = [] |
| 84 | total_lines = 0 | 152 | total_lines = 0 |
| 153 | _gen_3 = len | ||
| 154 | _gen_12 = digest | ||
| 155 | _gen_13 = results.append | ||
| 85 | for record in event["Records"]: | 156 | for record in event["Records"]: |
| 86 | lines = record["body"].split("\n") | 157 | lines = record["body"].split("\n") |
| 87 | total_lines += len(lines) | 158 | total_lines += _gen_3(lines) |
| 88 | d = digest(lines) | 159 | d = _gen_12(lines) |
| 89 | d["messageId"] = record.get("messageId") | 160 | d["messageId"] = record.get("messageId") |
| 90 | results.append(d) | 161 | _gen_13(d) |
| 91 | body = {"records": len(results), "lines": total_lines, "digests": results} | 162 | body = {"records": len(results), "lines": total_lines, "digests": results} |
| 92 | return {"statusCode": 200, "headers": {"content-type": "application/json"}, "body": json.dumps(body, sort_keys=True)} | 163 | return {"statusCode": 200, "headers": {"content-type": "application/json"}, "body": json.dumps(body, sort_keys=True)} |
The patch shown is the one release 1.4.8 writes for this sample, with generated names and comments edited out as said above. Before that editing it is byte for byte the patch of the 2026-11-12 Lambda run, which was made with a development version before 1.4.8.
Measured: AWS Lambda, us-east-1, python3.12, 512 MB, x86_64, one temporary copy per version, deleted afterwards
| Run | Date | Original p50 | Optimized p50 | Ratio | Mean billed time | Cost per million calls | Warm calls per version | Answers |
|---|---|---|---|---|---|---|---|---|
| First run | 2026-11-12 | 75.2 ms | 17.0 ms | 4.44x | 76.7 to 16.8 ms | $0.84 to $0.34 | 6 (3 events) | identical |
| Second run | 2026-11-12 | 75.0 ms | 16.1 ms | 4.67x | 75.8 to 15.7 ms | $0.83 to $0.33 | 12 (3 events) | identical |
Checked by: identical answers on the 3 recorded events.
Memory size and processor type (original code, same day)
A separate command tries settings on temporary copies. The cheapest setting is not the fastest: the choice is yours.
| Setting | p50 | Cost per million calls | Answers |
|---|---|---|---|
| 512 MB x86_64 (current) | 79.8 ms | $0.94 | same |
| 128 MB arm64 (cheapest) | 246.0 ms | $0.63 | same |
| 1024 MB arm64 | 29.9 ms | $0.67 | same |
| 3008 MB x86_64 (fastest) | 21.9 ms | $1.69 | same |
4 of the 14 settings tried are shown; 129 calls in all, so only a few calls per setting.
2. Order enrichment function with a database
gain measured on Lambdaanswers identicalLooks up a customer and a product for each order in a SQLite database file packaged with the function. A database reached over a network was not measured.
On a narrow screen, scroll the listing sideways: the optimized version is on the right.
| Original: lambda_function.py | Optimized by the product | ||
|---|---|---|---|
| unchanged lines not shown | |||
| 7 | import json | 7 | import json |
| 8 | import os | 8 | import os |
| 9 | import sqlite3 | 9 | import sqlite3 |
| 10 | [ 39 lines of generated helper code not shown here; they are in the real patch ] | ||
| 10 | 49 | ||
| 11 | DB_PATH = os.environ.get("ORDERS_DB", os.path.join(os.path.dirname(os.path.abspath(__file__)), "orders.db")) | 50 | DB_PATH = os.environ.get("ORDERS_DB", os.path.join(os.path.dirname(os.path.abspath(__file__)), "orders.db")) |
| 12 | CUSTOMER_SQL = "SELECT name, tier, region FROM customers WHERE id = ?" | 51 | CUSTOMER_SQL = "SELECT name, tier, region FROM customers WHERE id = ?" |
| unchanged lines not shown | |||
| 29 | orders = (event or {}).get("orders") or [] | 68 | orders = (event or {}).get("orders") or [] |
| 30 | cur = connection().cursor() | 69 | cur = connection().cursor() |
| 31 | lines = [] | 70 | lines = [] |
| 32 | for o in orders: | 71 | _gen_1 = list(orders) |
| 33 | cur.execute(CUSTOMER_SQL, (o["customer_id"],)) | 72 | try: |
| 34 | row = cur.fetchone() | 73 | _gen_2 = [o['customer_id'] for o in _gen_1] |
| 74 | except Exception: | ||
| 75 | _gen_2 = None | ||
| 76 | _gen_3 = _gen_4(cur, CUSTOMER_SQL, _gen_2) if _gen_2 is not None else None | ||
| 77 | try: | ||
| 78 | _gen_5 = [o['product_id'] for o in _gen_1] | ||
| 79 | except Exception: | ||
| 80 | _gen_5 = None | ||
| 81 | _gen_6 = _gen_4(cur, PRODUCT_SQL, _gen_5) if _gen_5 is not None else None | ||
| 82 | _gen_7 = lines.append | ||
| 83 | for o in _gen_1: | ||
| 84 | _gen_8 = o['customer_id'] | ||
| 85 | if _gen_3 is not None and _gen_8 in _gen_3: | ||
| 86 | row = _gen_3[_gen_8] | ||
| 87 | else: | ||
| 88 | cur.execute(CUSTOMER_SQL, (o["customer_id"],)) | ||
| 89 | row = cur.fetchone() | ||
| 35 | if row is None: | 90 | if row is None: |
| 36 | lines.append({"order": o["id"], "error": "unknown customer"}) | 91 | _gen_7({"order": o["id"], "error": "unknown customer"}) |
| 37 | continue | 92 | continue |
| 38 | name, tier, region = row | 93 | name, tier, region = row |
| 39 | cur.execute(PRODUCT_SQL, (o["product_id"],)) | 94 | _gen_9 = o['product_id'] |
| 40 | prow = cur.fetchone() | 95 | if _gen_6 is not None and _gen_9 in _gen_6: |
| 96 | prow = _gen_6[_gen_9] | ||
| 97 | else: | ||
| 98 | cur.execute(PRODUCT_SQL, (o["product_id"],)) | ||
| 99 | prow = cur.fetchone() | ||
| 41 | if prow is None: | 100 | if prow is None: |
| 42 | lines.append({"order": o["id"], "error": "unknown product"}) | 101 | _gen_7({"order": o["id"], "error": "unknown product"}) |
| 43 | continue | 102 | continue |
| 44 | sku, unit_price, weight_g = prow | 103 | sku, unit_price, weight_g = prow |
| 45 | gross = unit_price * o["qty"] | 104 | gross = unit_price * o["qty"] |
| 46 | net = gross * (100 - TIER_DISCOUNT.get(tier, 0)) // 100 | 105 | net = gross * (100 - TIER_DISCOUNT.get(tier, 0)) // 100 |
| 47 | lines.append({"order": o["id"], "customer": name, "region": region, "sku": sku, "qty": o["qty"], "net_cents": net, "weight_g": weight_g * o["qty"]}) | 106 | _gen_7({"order": o["id"], "customer": name, "region": region, "sku": sku, "qty": o["qty"], "net_cents": net, "weight_g": weight_g * o["qty"]}) |
| 48 | by_region, weight = {}, 0 | 107 | by_region, weight = {}, 0 |
| 49 | for ln in lines: | 108 | for ln in lines: |
| 50 | if "error" not in ln: | 109 | if "error" not in ln: |
| unchanged lines not shown | |||
| 52 | weight += ln["weight_g"] | 111 | weight += ln["weight_g"] |
| 53 | digest = hashlib.sha256(json.dumps(lines, sort_keys=True).encode()).hexdigest() | 112 | digest = hashlib.sha256(json.dumps(lines, sort_keys=True).encode()).hexdigest() |
| 54 | report = {} | 113 | report = {} |
| 114 | _gen_10 = sum | ||
| 115 | _gen_11 = max | ||
| 116 | _gen_12 = len | ||
| 117 | _gen_13 = str | ||
| 55 | for cid in (event or {}).get("report_customers") or []: | 118 | for cid in (event or {}).get("report_customers") or []: |
| 56 | cur.execute(HISTORY_SQL, (cid,)) | 119 | cur.execute(HISTORY_SQL, (cid,)) |
| 57 | rows = cur.fetchall() | 120 | rows = cur.fetchall() |
| 58 | units = sum(r[0] for r in rows) | 121 | units = _gen_10(r[0] for r in rows) |
| 59 | cur.execute(HISTORY_SQL, (cid,)) | 122 | cur.execute(HISTORY_SQL, (cid,)) |
| 60 | rows = cur.fetchall() | 123 | rows = cur.fetchall() |
| 61 | biggest = max(r[0] for r in rows) if rows else 0 | 124 | biggest = _gen_11(r[0] for r in rows) if rows else 0 |
| 62 | cur.execute(RECENT_SQL, (cid,)) | 125 | cur.execute(RECENT_SQL, (cid,)) |
| 63 | recent = len(cur.fetchall()) | 126 | recent = _gen_12(cur.fetchall()) |
| 64 | report[str(cid)] = {"units": units, "biggest": biggest, "recent_lines": recent} | 127 | report[_gen_13(cid)] = {"units": units, "biggest": biggest, "recent_lines": recent} |
| 65 | return {"by_region": dict(sorted(by_region.items())), "weight_g": weight, "orders": len(orders), "errors": sum("error" in ln for ln in lines), "lines_sha256": digest, "first": lines[:3], | 128 | return {"by_region": dict(sorted(by_region.items())), "weight_g": weight, "orders": len(orders), "errors": sum("error" in ln for ln in lines), "lines_sha256": digest, "first": lines[:3], |
| 66 | "report": report} | 129 | "report": report} |
The patch shown is the one release 1.4.8 writes for this sample, with generated names and comments edited out as said above. Before that editing it is byte for byte the patch of the 2026-11-12 Lambda run, which was made with a development version before 1.4.8.
Measured: AWS Lambda, us-east-1, python3.12, 512 MB, x86_64, one temporary copy per version, deleted afterwards
| Run | Date | Original p50 | Optimized p50 | Ratio | Mean billed time | Cost per million calls | Warm calls per version | Answers |
|---|---|---|---|---|---|---|---|---|
| One run | 2026-11-12 | 76.0 ms | 34.1 ms | 2.23x | 76.6 to 34.8 ms | $0.84 to $0.49 | 27 (3 events) | identical |
Checked by: identical answers on the 3 recorded events.
When the product declines to judge: a local check of the same package with 1.4.8 on 2026-11-29, on a busy shared computer, answered INCONCLUSIVE: the passes disagree (0.83x, 0.89x, 1.66x): this machine was too busy to judge. Those three figures are not performance results.
3. Rejected: a compute function that did not get faster
rejected: no gainanswers identicalA function made of pure-Python computing tasks. The product changed 22 places; the real service showed no difference in the median time.
Show the changes (workloads.py)
On a narrow screen, scroll the listing sideways: the optimized version is on the right.
| Original: workloads.py | Optimized by the product | ||
|---|---|---|---|
| unchanged lines not shown | |||
| 14 | from fractions import Fraction | 14 | from fractions import Fraction |
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | # ---- generated comment (text edited out) ---- | ||
| 18 | try: | ||
| 19 | _gen_1 = re.compile('\\d+') | ||
| 20 | except re.error: | ||
| 21 | _gen_1 = None | ||
| 22 | |||
| 23 | |||
| 17 | def nbody(steps): | 24 | def nbody(steps): |
| 18 | bodies = [[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 39.47841760435743], [4.84, -1.16, -0.10, 0.606, 2.81, -0.025, 0.037], [8.34, 4.12, -0.40, -1.01, 1.82, 0.008, 0.011], | 25 | bodies = [[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 39.47841760435743], [4.84, -1.16, -0.10, 0.606, 2.81, -0.025, 0.037], [8.34, 4.12, -0.40, -1.01, 1.82, 0.008, 0.011], |
| 19 | [12.89, -15.11, -0.22, 1.08, 0.868, -0.010, 0.0017], [15.37, -25.91, 0.179, 0.979, 0.594, -0.034, 0.002]] | 26 | [12.89, -15.11, -0.22, 1.08, 0.868, -0.010, 0.0017], [15.37, -25.91, 0.179, 0.979, 0.594, -0.034, 0.002]] |
| 20 | dt = 0.01 | 27 | dt = 0.01 |
| 28 | _gen_2 = range | ||
| 29 | _gen_3 = len | ||
| 30 | _gen_4 = math.sqrt | ||
| 21 | for _ in range(steps): | 31 | for _ in range(steps): |
| 22 | for i in range(len(bodies)): | 32 | for i in _gen_2(_gen_3(bodies)): |
| 23 | bi = bodies[i] | 33 | bi = bodies[i] |
| 24 | for j in range(i + 1, len(bodies)): | 34 | for j in _gen_2(i + 1, _gen_3(bodies)): |
| 25 | bj = bodies[j] | 35 | bj = bodies[j] |
| 26 | dx, dy, dz = bi[0] - bj[0], bi[1] - bj[1], bi[2] - bj[2] | 36 | dx, dy, dz = bi[0] - bj[0], bi[1] - bj[1], bi[2] - bj[2] |
| 27 | d2 = dx * dx + dy * dy + dz * dz | 37 | d2 = dx * dx + dy * dy + dz * dz |
| 28 | mag = dt / (d2 * math.sqrt(d2)) | 38 | mag = dt / (d2 * _gen_4(d2)) |
| 29 | bi[3] -= dx * bj[6] * mag; bi[4] -= dy * bj[6] * mag; bi[5] -= dz * bj[6] * mag | 39 | bi[3] -= dx * bj[6] * mag; bi[4] -= dy * bj[6] * mag; bi[5] -= dz * bj[6] * mag |
| 30 | bj[3] += dx * bi[6] * mag; bj[4] += dy * bi[6] * mag; bj[5] += dz * bi[6] * mag | 40 | bj[3] += dx * bi[6] * mag; bj[4] += dy * bi[6] * mag; bj[5] += dz * bi[6] * mag |
| 31 | for b in bodies: | 41 | for b in bodies: |
| unchanged lines not shown | |||
| 35 | 45 | ||
| 36 | def fannkuch(n): | 46 | def fannkuch(n): |
| 37 | perm1, count, maxflips, checksum, r, nperm = list(range(n)), [0] * n, 0, 0, n, 0 | 47 | perm1, count, maxflips, checksum, r, nperm = list(range(n)), [0] * n, 0, 0, n, 0 |
| 48 | _gen_5 = max | ||
| 49 | _gen_2 = range | ||
| 38 | while True: | 50 | while True: |
| 39 | while r != 1: | 51 | while r != 1: |
| 40 | count[r - 1] = r; r -= 1 | 52 | count[r - 1] = r; r -= 1 |
| unchanged lines not shown | |||
| 45 | perm[:k + 1] = perm[k::-1] | 57 | perm[:k + 1] = perm[k::-1] |
| 46 | flips += 1 | 58 | flips += 1 |
| 47 | k = perm[0] | 59 | k = perm[0] |
| 48 | maxflips = max(maxflips, flips) | 60 | maxflips = _gen_5(maxflips, flips) |
| 49 | checksum += flips if nperm % 2 == 0 else -flips | 61 | checksum += flips if nperm % 2 == 0 else -flips |
| 50 | while True: | 62 | while True: |
| 51 | if r == n: | 63 | if r == n: |
| 52 | return f"{checksum} {maxflips}" | 64 | return f"{checksum} {maxflips}" |
| 53 | p0 = perm1[0] | 65 | p0 = perm1[0] |
| 54 | for i in range(r): | 66 | for i in _gen_2(r): |
| 55 | perm1[i] = perm1[i + 1] | 67 | perm1[i] = perm1[i + 1] |
| 56 | perm1[r] = p0 | 68 | perm1[r] = p0 |
| 57 | count[r] -= 1 | 69 | count[r] -= 1 |
| unchanged lines not shown | |||
| 78 | rng = random.Random(7) | 90 | rng = random.Random(7) |
| 79 | data = [{"id": i, "name": f"item{i}", "tags": [rng.choice("abcdef") for _ in range(5)], "value": rng.random() * 1000, "nested": {"a": [i, i * 2, i * 3], "b": {"c": str(i)}}} for i in range(n)] | 91 | data = [{"id": i, "name": f"item{i}", "tags": [rng.choice("abcdef") for _ in range(5)], "value": rng.random() * 1000, "nested": {"a": [i, i * 2, i * 3], "b": {"c": str(i)}}} for i in range(n)] |
| 80 | s = json.dumps(data, sort_keys=True) | 92 | s = json.dumps(data, sort_keys=True) |
| 93 | _gen_6 = json.loads | ||
| 94 | _gen_7 = json.dumps | ||
| 81 | for _ in range(3): | 95 | for _ in range(3): |
| 82 | back = json.loads(s); s = json.dumps(back, sort_keys=True) | 96 | back = _gen_6(s); s = _gen_7(back, sort_keys=True) |
| 83 | return hashlib.md5(s.encode()).hexdigest() | 97 | return hashlib.md5(s.encode()).hexdigest() |
| 84 | 98 | ||
| 85 | 99 | ||
| unchanged lines not shown | |||
| 88 | words = ["alpha", "beta", "gamma", "delta", "epsilon", "2024-01-02", "user@example.com", "192.168.1.1", "https://hpc-labs.ai/x", "0x1F"] | 102 | words = ["alpha", "beta", "gamma", "delta", "epsilon", "2024-01-02", "user@example.com", "192.168.1.1", "https://hpc-labs.ai/x", "0x1F"] |
| 89 | text = " ".join(rng.choice(words) + str(rng.randrange(1000)) for _ in range(n)) | 103 | text = " ".join(rng.choice(words) + str(rng.randrange(1000)) for _ in range(n)) |
| 90 | pats = [r"\d{4}-\d{2}-\d{2}", r"[a-z]+@[a-z]+\.[a-z]+", r"\b\d{1,3}(?:\.\d{1,3}){3}\b", r"https?://[^\s]+", r"\b(alpha|gamma)\d*\b", r"0x[0-9A-F]+"] | 104 | pats = [r"\d{4}-\d{2}-\d{2}", r"[a-z]+@[a-z]+\.[a-z]+", r"\b\d{1,3}(?:\.\d{1,3}){3}\b", r"https?://[^\s]+", r"\b(alpha|gamma)\d*\b", r"0x[0-9A-F]+"] |
| 91 | out = [len(re.findall(p, text)) for p in pats] + [len(re.sub(r"\d+", "#", text))] | 105 | out = [len(re.findall(p, text)) for p in pats] + [len((_gen_1.sub("#", text) if _gen_1 is not None else re.sub(r"\d+", "#", text)))] |
| 92 | return repr(out) | 106 | return repr(out) |
| 93 | 107 | ||
| 94 | 108 | ||
| unchanged lines not shown | |||
| 96 | rng = random.Random(3) | 110 | rng = random.Random(3) |
| 97 | obj = {i: (str(i), [rng.random() for _ in range(10)], {"k": i, "t": tuple(range(i % 7))}) for i in range(n)} | 111 | obj = {i: (str(i), [rng.random() for _ in range(10)], {"k": i, "t": tuple(range(i % 7))}) for i in range(n)} |
| 98 | s = pickle.dumps(obj, protocol=pickle.HIGHEST_PROTOCOL) | 112 | s = pickle.dumps(obj, protocol=pickle.HIGHEST_PROTOCOL) |
| 113 | _gen_8 = pickle.dumps | ||
| 114 | _gen_9 = pickle.loads | ||
| 99 | for _ in range(5): | 115 | for _ in range(5): |
| 100 | s = pickle.dumps(pickle.loads(s), protocol=pickle.HIGHEST_PROTOCOL) | 116 | s = _gen_8(_gen_9(s), protocol=pickle.HIGHEST_PROTOCOL) |
| 101 | return hashlib.md5(s).hexdigest() | 117 | return hashlib.md5(s).hexdigest() |
| 102 | 118 | ||
| 103 | 119 | ||
| unchanged lines not shown | |||
| 106 | xs = [rng.random() for _ in range(n)] | 122 | xs = [rng.random() for _ in range(n)] |
| 107 | ys = sorted(xs); zs = sorted(xs, key=lambda v: -v); ws = sorted((str(v)[2:8] for v in xs)) | 123 | ys = sorted(xs); zs = sorted(xs, key=lambda v: -v); ws = sorted((str(v)[2:8] for v in xs)) |
| 108 | d = {} | 124 | d = {} |
| 125 | _gen_10 = int | ||
| 109 | for i, v in enumerate(xs): | 126 | for i, v in enumerate(xs): |
| 110 | d[int(v * 1000)] = d.get(int(v * 1000), 0) + i | 127 | d[_gen_10(v * 1000)] = d.get(_gen_10(v * 1000), 0) + i |
| 111 | return repr((round(sum(ys[:10]), 12), round(zs[0], 12), ws[0], ws[-1], sum(d.values()) % 1000003, len(set(ws)))) | 128 | return repr((round(sum(ys[:10]), 12), round(zs[0], 12), ws[0], ws[-1], sum(d.values()) % 1000003, len(set(ws)))) |
| 112 | 129 | ||
| 113 | 130 | ||
| unchanged lines not shown | |||
| 157 | 174 | ||
| 158 | def float_math(n): | 175 | def float_math(n): |
| 159 | acc = 0.0 | 176 | acc = 0.0 |
| 177 | _gen_11 = math.atan2 | ||
| 178 | _gen_12 = math.hypot | ||
| 179 | _gen_13 = math.log1p | ||
| 180 | _gen_14 = math.exp | ||
| 181 | _gen_15 = math.sin | ||
| 182 | _gen_16 = math.cos | ||
| 160 | for i in range(1, n): | 183 | for i in range(1, n): |
| 161 | x = i * 0.001 | 184 | x = i * 0.001 |
| 162 | acc += math.sin(x) * math.cos(x) + math.exp(-x) + math.log1p(x) + math.atan2(x, 1.5) + math.hypot(x, 2.0) ** 0.5 | 185 | acc += _gen_15(x) * _gen_16(x) + _gen_14(-x) + _gen_13(x) + _gen_11(x, 1.5) + _gen_12(x, 2.0) ** 0.5 |
| 163 | return repr(round(acc, 6)) | 186 | return repr(round(acc, 6)) |
| 164 | 187 | ||
| 165 | 188 | ||
| unchanged lines not shown | |||
The patch shown is the one release 1.4.8 writes for this sample, with generated names and comments edited out as said above. Before that editing it is byte for byte the patch of the 2026-11-12 Lambda run, which was made with a development version before 1.4.8.
Measured: AWS Lambda, us-east-1, python3.12, 512 MB, x86_64, one temporary copy per version, deleted afterwards
| Run | Date | Original p50 | Optimized p50 | Ratio | Mean billed time | Cost per million calls | Warm calls per version | Answers |
|---|---|---|---|---|---|---|---|---|
| One run | 2026-11-12 | 925.2 ms | 925.2 ms | 1.00x | 1093.6 to 1043.7 ms | $9.31 to $8.90 | 54 (6 events) | identical |
The median is the same. Mean billed time was 4.6 % lower, which is far inside the instance-to-instance difference described above, so it is not claimed as a gain.
The recorded reason of release 1.4.8
Local check of the same package, 2026-11-29, on a shared Arm computer (indicative only, not a Lambda figure):
NO GAIN (1.02x (1.00x, 1.04x, 1.01x per pass): under the 1.05x that is called a gain, or not in every pass). The optimized package is NOT a result: it was moved to rejected/ for inspection only. Keep the original package.