Mobile Development 8 min read

Design and Implementation of a High‑Performance, High‑Availability Logging System for iOS Apps

This article describes the motivation, design choices, memory‑mapped implementation, performance evaluation, and practical lessons learned while building a lightweight, crash‑resilient logging framework for the 运满满 iOS client, highlighting its superiority over traditional file‑write approaches.

Manbang Technology Team
Manbang Technology Team
Manbang Technology Team
Design and Implementation of a High‑Performance, High‑Availability Logging System for iOS Apps

The original iOS client lacked a comprehensive logging system, forcing developers to rely on user‑reported crashes and manual reproduction, which often proved impossible in a large codebase with many potential root causes.

To reliably capture user logs even during severe crashes, a high‑performance, high‑availability solution was required that could ingest logs quickly and guarantee no loss.

Common industry approaches were evaluated: direct file writes (reliable but slow), in‑memory cache writes (fast but vulnerable to loss on crash), and memory‑mapped file writes (fast and reliable but more complex to implement).

After comparing trade‑offs, the team chose a memory‑mapped (mmap) logging strategy. Although the open‑source Mars component uses mmap, its large binary size made it unsuitable, so a lightweight custom logger was developed.

Memory‑mapping maps a file into the process address space, allowing the app to write logs via pointers; the OS automatically flushes changes to disk, eliminating an extra copy step and improving throughput.

On startup the logger maps a 100 KB contiguous region; if mmap fails it falls back to a cache‑buffer write. Existing unmapped logs are flushed, then each new log entry is formatted with level, timestamp, module, method, line number, encrypted, and written to the MMapBuffer.

Buffer flushes occur when the buffer exceeds 75 % capacity, when the system issues a memory‑warning, on fatal errors, or when the app moves to the background.

Performance tests compared three methods—real‑time file writes, Mars, and the new YMMLogLib—by logging 200‑byte messages at scales from 1 k to 50 k entries. Results showed YMMLogLib matching Mars and outperforming real‑time writes by over 70 %.

Practical insights include preferring C‑level string handling over Objective‑C for speed, replacing unsafe strlen calls with pre‑computed lengths to avoid truncation caused by embedded null bytes, and accounting for the difference between NSString character count and UTF‑8 byte length for Chinese characters.

The self‑developed logger was released in August, quickly aiding issue diagnosis across multiple services, and future versions will add server‑pull capabilities with ECC‑encrypted logs to further improve debugging without disturbing users.

Mobile DevelopmentPerformanceiOSloggingencryptionmemory-mapped
Manbang Technology Team
Written by

Manbang Technology Team

Manbang Technology Team

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.