14Performance Optimisation

libexpat Optimization

#ModelScoreStepsIn tokOut tokAvg costAvg time
1Claude Fable 5.1
0.4661
±0.110
1,238534.3M1.4M$301.5713.7h
2GPT-5.6
0.3143
±0.043
30180.1M220k$78.141.8h
3GLM-5.3
0.1616
±0.096
1,873838.6M1.4M$229.1814.3h
4Gemini 3.7 Flash
0.1105
±0.106
838324.7M836k$34.173.7h
5Kimi K3
0.0916
±0.085
1,390599.3M1.5M$210.3818.2h
6Grok 4.6
0.0779
±0.073
403100.5M626k$100.763.3h
7DeepSeek V4 Flash Exp
0.0287
±0.041
2,6901228.5M2.1M$20.469.5h
8Inkling
0.0000
±0.000
17210.8M43k$10.440.4h
9Muse Spark 1.2
0.0000
±0.000
417140.3M675k$34.193.1h
10Qwen3.8-Max
0.0000
±0.000
23230.8M1.8M$18.9719.9h

Background

libexpat is a widely used stream-oriented XML parser: callers register handlers, feed a document whole or in arbitrary chunks, and receive parse events in order. Reproducing it in hand-written assembly means matching not just well-formed parsing but libexpat's exact observable behaviour: the same events in the same order, the same coalescing of character data, and on malformed input the same specific error code, not merely an error. Chunked feeding is where from-scratch parsers first diverge: a construct can split across calls at any byte, so the parser must carry partial state and still emit exactly what a one-shot parse would.

The parser's C implementation is withheld: the agent gets the public API headers as the specification, example documents with their expected event traces, and nothing else to copy from. The performance bar makes assembly the point rather than a gimmick: the deliverable must get through a document doing measurably less work than libexpat's own compiled C.

Task

Ship /app/asm-port/libexpat.so, assembled from the *.s/*.S/*.asm sources in /app/asm-port/: a System V AMD64 C-ABI shared library implementing the interface in /app/tests/expat.h.

  • Thirteen entry points are resolved by name, from XML_ParserCreate and the handler setters through XML_Parse, XML_GetErrorCode, and XML_ParserFree; a partial library still loads and runs.
  • Every document is parsed four ways (namespace processing off and on, one-shot and chunked), and all four must agree with libexpat: same events, same order, same final status and error code.
  • Correctness is all-or-nothing: one wrong document takes the result to zero however fast the rest are.
  • libc may be called from assembly (malloc, memcpy, memchr, …) and is the expected way to get memory, but its work is priced like the agent's own.
  • Target x86-64-v3 and no higher: the measurement simulator has no AVX-512, and an unmeasurable parse is no better than a wrong one.
  • Changes are confined to /app/asm-port/.

What The Agent Gets

The ABI headers (/app/tests/expat.h, expat_external.h), example documents at /app/tests/corpus/ with the expected event traces for all four modes at /app/tests/expected/, and the C source of the workers that produce and measure those traces. /app/build-lib.sh assembles and links the deliverable (nasm/as/ld, no C-compilation step anywhere); /app/run-tests.sh diffs the parser's events against libexpat's on every example document; /app/perf-check measures what one parse costs against the reference numbers baked in /app/baseline-work.json, over the benchmark documents in /app/bench/. The measurement stack itself is readable at /app/performance/, and /app/workloads.py defines the workload space: nine document shapes, any size in the 64–192 KB band, any of the four modes. The machine is offline, with nasm, as, ld, gdb, and valgrind preinstalled.

Verification

A clean-room verifier, separate from the agent's environment, assembles the submission from its assembly sources alone and replays it over a root-only scored corpus drawn deterministically from the W3C XML Conformance Test Suite, including mutated twin documents, so a table of memorized traces is not an implementation. Every scored unit (a document in one of the four parse modes) must hash-match the trace of the reference libexpat 2.6.4 build; one wrong unit zeroes the result, with the unit pass rate kept only as a diagnostic.

  • Once fully correct, the reward is 2**u - 1 where u scales the geometric mean of reference-to-candidate work ratios, reaching full credit at 7x; doing no better than libexpat scores zero.
  • Work is whole-process instruction-priced measurement (callgrind-based per-opcode throughput pricing plus a capped branch-mispredict term, no cache term). It is deterministic, so one run per change is enough and host speed does not matter.
  • Anti-cheat gates: no withheld expat C files in the deliverable, hard-failing source scans for dlopen/dlsym, Python/pyexpat delegation, and .incbin; an ELF import check restricted to libc; a preloaded guard that refuses loading a foreign XML library; and a no-exec seccomp filter during measured parses. Large binary files under /app are read as a parser carried in as data.
  • A work-linearity gate and a native wall-time audit catch submissions that skip priced iterations; if fewer than 75% of documents could be measured, the trial is marked invalid rather than scored.

Environment

Base imageubuntu:24.04
Tools availableC/C++ toolchain, Python 3
Compute4 CPUs · 8 GB RAM
Time limit20h

Changes From V1

This task is an improved revision of libexpat to x86-64 Assembly from FrontierSWE V1.

  • V1 shipped libexpat's complete C source in the workspace as the specification; V2 withholds the implementation entirely: the agent gets only the public headers, example documents, and expected traces, and shipping any withheld C file is a hard anti-cheat failure.
  • The correctness target changed from compiling C test programs against the full ~60-function ABI to exact event-trace and error-code equivalence with a reference expat 2.6.4 build over a W3C conformance-suite corpus, in four parse modes including chunked feeding, narrowed to 13 dlsym-resolved entry points and made all-or-nothing.
  • Performance became the graded axis: after the correctness gate, the score is the geometric mean of deterministic instruction-priced work ratios against the reference, with full credit at 7x; V1 shipped expat's upstream wall-clock benchmark alongside weighted test modules.
  • Anti-cheat moved out of the agent's container: V1 hid gcc, python3, and the system libexpat behind encrypted bundles inside the same image; V2 verifies in a separate clean-room container with pinned images, ELF import checks, source scans, a preloaded dlopen guard, and a no-exec seccomp filter during measurement.
  • Infrastructure was rebuilt on the current harbor schema: the verifier timeout dropped from 86400 s to 9000 s, the /app/.timer file tree was replaced by the sandbox-timer CLI, and both agent and verifier images are pinned by content hash.

References

  • libexpat (Expat XML parser) (MIT): The pinned 2.6.4 C library, cloned at image build (nothing vendored), builds the verifier-only reference libexpat.so whose parse-event traces are the answer key: real expat is the oracle. The agent receives only the public API headers and reference-produced traces; the C implementation is withheld.
  • W3C XML Conformance Test Suite (xmlts) (W3C 3-clause BSD test-suite license option): A deterministic, self-contained XML 1.0 slice of the suite's test documents becomes the scored corpus (root-only) and a small disjoint visible slice of worked examples; the BSD election permits the derived mutated twins. James Clark's xmltest collection is excluded to honour its redistribute-only-intact terms. Fetched at a pinned sha256 at image build; no conformance claim is made.
  • uops.info instruction data (Derived aggregate; format via andreas-abel/XED-to-XML (Apache-2.0)): The per-opcode cost table used by the measurement stack is a derived aggregate of reciprocal-throughput measurements from uops.info (Abel & Reineke, ASPLOS 2019), generated once offline; it is not a copy of the dataset.