Skip to content

bug: graphics: vec2 ceil and floor regress against C code generation #1298

Closed

Description

@zackees

Part of #1295.

Context and reproduction

Class: performance regression / release-gate investigation.

Per-component .ceil() and .floor() reach the C ABI vec2 wrappers. On the measured x86_64 target, objdump shows two indirect rounding calls from Rust vec2_ceil; the C oracle emits rounding operations inline without calls.

Benchmark Rust ns C ns Rust/C Paired run ratio range
vec2/ceil 8.940 3.615 2.473× 1.698–2.618×
vec2/floor 8.945 5.214 1.716× 1.705–2.384×

Location

Profiling evidence

A 5 s vec2/ceil/rust profile collected 956 samples, none lost; ceilf has 13.62% self cycles and vec2_ceil 8.04%, with the Criterion iteration loop dominating the rest. Disassembly is stronger evidence of the extra calls than an attempt to assign nanosecond call overhead from samples.

Proposed fix and failing-test sketch

Investigate target-feature baseline and Rust/LLVM lowering, then choose compatible code generation without raising the supported CPU baseline globally. Preserve signed zero, NaN/infinity behavior and differential parity.

Acceptance criteria

  • Establish RED evidence before coding: reproduce the affected benchmark cases with five paired release passes, median and range; isolate a stable regression from measurement noise. Keep the baseline/command/CPU/source identity.
  • Implement only demonstrated causes, then show GREEN: affected hot-path median Rust/C ratios at or below 1.10 on the same release target, or an explicit separate acceptance of the remaining measured user impact under docs/rust-port/release-criteria.md. For unstable candidates, a reproducible negative result with evidence can close the investigation without a code change.
  • Preserve the public C ABI and allocation contracts. Run affected Rust unit/layout/differential tests and unchanged C tests against both libobs variants for any implementation change; document any inapplicable tier. Keep malformed-input/fuzz and floating-point parity coverage where relevant. Do not edit public headers or existing C tests to make a change pass.
  • Recheck related cases to show the optimization does not transfer cost elsewhere; record absolute times as well as ratios. Functional correctness alone does not close a performance issue.

Decisions

P2: consistent measured regression, with a concrete code-generation difference. Benchmark input sizes stay together because they exercise the same implementation path. No claim is made that a synthetic ratio equals user-visible frame-time impact.

Measurement context

Measured on 2026-10-17, AMD Ryzen 7 3700X, Linux x86_64, CPU affinity 7, Rust 1.98.1, GCC 15.2.0. Five complete passes of all 70 paired Criterion comparisons; 30 samples/case/pass, 0.1 s warmup, 0.4 s measurement, 10,000 resamples. Values below are medians of the five pass medians. The ratio range contains the five paired Rust/C ratios; the reported median ratio divides the two backend medians.

CARGO_PROFILE_BENCH_DEBUG=1 RUSTFLAGS='-C force-frame-pointers=yes' \
  uv run rust/tools/benchmarks/record.py --cpu 7 --repeats 5 --output baseline.json

The optimized profiling build completed in 40.99 s. Recorded end-of-run HEAD: b56092cc66a979b2f543da20846b965c3517ac36. The checkout was shared and HEAD moved during work; the recorder's source fingerprint stayed unchanged across all five timing passes: 5eea3716b30cf03831eacbc1f06711c2c622f915ebd8945a6940e6fab9d0d422. Source links use fetched master; the fingerprint identifies the measured benchmark/implementation input set. Baseline JSON SHA-256: 9517eb96c66a484cf305a13758a856d893f4608ee454c1a6ea16f693f62c4f26.

This was a shared host. The application build ran on CPUs 0–3 during part of the CPU-7 benchmark run, and other workloads were present. Wide ranges and nanosecond-scale differences require confirmation on quiet release hardware. A descriptive threshold crossing is not proof of statistical significance. The C oracle uses Cargo's optimized C build, rather than full OBS C IPO; profiling frame pointers also affect tiny call costs. No cross-platform or whole-application speedup/slowdown is inferred from shim benchmarks. dstr/printf_control remains C in both configurations and is excluded from Rust regression decisions.

Local evidence: /home/niteris/dev/obs-rust/reports/obs-profile-20261017/ contains baseline.json (per-run medians/confidence intervals), build logs, perf data/reports, assembly, runtime logs/maps/results, and the profiling harness. Raw Criterion samples are in target/criterion, baselines ports-20261017T172745Z-1 through ports-20261017T172745Z-5. Key evidence is reproduced here so triage does not depend on local file access.

Activity

  1. zackees commented on Oct 18, 2026

    @zackees
    MemberAuthor

    Claiming. Plan: find out why C gets inline rounding at the same target (compare GCC's baseline x86-64 sequence with what LLVM emits for f32::ceil/floor without SSE4.1), then do the same in Rust without raising the global CPU baseline: a branch-free inline ceil/floor that keeps signed zero, NaN, infinities and large values, or a function-level SSE4.1 path with runtime detection if that's the established pattern. Tier 3 parity against the C oracle covers the edge values; the evidence is before/after disassembly plus benchmarks.

  2. added
    claimed
    on Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    claimed

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions