I Benchmarked My Custom Language on a $150 Phone. 1 Core Beat 8 Cores. Hereโs Why.
Good morning? No. God morning. ๐
I just finished the v2.5.0-pre benchmark stress test for my custom programming language, H-code. I ran it on my POCO C55 (MediaTek Helio G85, 8 cores, 4GB RAM) entirely inside Termux.
I expected to see my 8-thread parallel implementation crush the single-threaded version. I was wrong. The results completely broke my understanding of how this hardware works, and they taught me more about compiler design than any textbook ever could.
Here is the story of how my language pushed a $150 phone to its absolute physical limits, and the brutal truths the silicon told me.
๐งฑ 1. The Android Walled Garden (GPU is a Lie)
My phone has an ARM Mali-G52 MC2 GPU. I wanted to use it for parallel compute. I wrote a C probe to dlopen the OpenCL drivers.
The file exists at /vendor/lib64/libOpenCL.so. But when I tried to load it, Android threw a BLOCKED error.
The truth: Since Android 7, the OS uses strict linker namespaces. Unprivileged apps (like Termux) are physically blocked from loading vendor libraries. The GPU is sitting right there, completely unused, locked behind a software wall. If you want GPU compute on Android without root, you are out of luck.
๐ 2. The Compiler Caught Its Own Lie
Before benchmarking, I ran the standard library verification. vec_mean([1, 2, 3, 4]) returned 2. The actual mean is 2.5.
Why did my language lie? Because H-code currently only supports Int[] arrays. The standard library was performing integer division and silently truncating the decimal. I caught my own language failing at basic math. Itโs now documented as a known defect until I implement Float[] arrays.
โ๏ธ 3. The Main Event: 1 Optimized Core vs 8 Threads
This is where it gets crazy. I wrote a dot-product kernel and ran it in two modes: Sequential (1 thread) and Parallel (8 POSIX threads).
First, I compiled with -O0 (no optimizations). The 8 threads won, giving a 2.61x speedup. Standard stuff.
Then, I compiled with -O2.
- Sequential (-O2): 20.38 ms
- Parallel x8 (-O2): 18.06 ms
Wait. The 8 threads only gave a 1.13x speedup. But look closer: The single-threaded -O2 version (20.38ms) was 2.80x faster than the 8-threaded -O0 version (57.10ms).
The Lesson: Clangโs auto-vectorization was so aggressive that a single optimized core absolutely destroyed eight unoptimized cores. Thread-level parallelism is useless if you aren't leveraging instruction-level parallelism first.
๐งฌ 4. Reading the Matrix (The Assembly Proof)
I didn't just trust the timer. I wanted to know how Clang got that 7.31x speedup at -O2. So I dumped the ARM64 assembly output (clang -S). I grepped the output and found the smoking gun:
smlal v0.2d, v4.2s, v5.2s
smlal2 v1.2d, v4.4s, v5.4s
Clang wasn't just running a loop. It was using NEON SIMD (Single Instruction, Multiple Data). It was using smlal (Signed Multiply-Accumulate Long) to process 4 integers at the exact same time, and it unrolled the loop 4 ways to hide latency. It was doing 8 multiply-accumulate operations per iteration. The compiler was doing the work of 8 cores, all inside a single core.
๐ 5. The Memory Bandwidth Ceiling
At -O2 with 20 million elements, the sequential version hit 7.85 GB/s of memory bandwidth. The parallel version hit 8.86 GB/s.
Why didn't the parallel version go faster? Because we hit the physical limit of the RAM. You cannot read data from DRAM faster than the physical wires allow. Adding more cores at this point just creates a traffic jam. The kernel became memory-bound, not compute-bound.
๐ก๏ธ 6. The DVFS Trap (How the Phone Lied to Me)
In my very first run, the 8-thread parallel version was actually slower than the sequential version (0.90x speedup). In the second run, it was 2.35x faster.
The code didn't change. The compiler didn't change. What changed? The phone woke up.
Android uses DVFS (Dynamic Voltage and Frequency Scaling). In the first run, the CPU cores were asleep at a low clock speed. The overhead of spawning 8 threads took longer than the actual math. By the second run, the CPU was "warm" and clocked up to 2.0 GHz. If you don't account for CPU frequency scaling, your benchmarks are meaningless.
๐ ๏ธ Whatโs Next for H-Code?
This benchmark broke a lot of things, and thatโs exactly what it was supposed to do.
- I need to implement Float[] arrays so
vec_meandoesn't truncate. - I need to build a persistent thread pool so we don't pay the spawn cost on every function call.
- I need to add an adaptive threshold so the language automatically falls back to sequential for small arrays.
H-code v2.5.0-pre isn't just a language update. It's a proof that you can do serious, silicon-level systems engineering on a $150 Android phone.
GitHub: https://github.com/harun-sket/H-code.git
NPM: https://www.npmjs.com/package/hcode-lang
If you want to see the full raw data, the assembly dumps, and the exact C code I used to trap the DVFS governor, check the repo. Let's keep pushing the limits. ๐ฏโ๏ธ๐
Comments
No comments yet. Start the discussion.