Skip to content

refactor: Simplify the codebase and reduce memory and SVG size - #3

Merged
Fuwn merged 18 commits into
mainfrom
refactor/audit-cleanup
Oct 24, 2026
Merged

Fuwn merged 18 commits into
mainfrom
refactor/audit-cleanup

Conversation

@Fuwn

@Fuwn Fuwn commented Oct 24, 2026

Copy link
Copy Markdown
Owner

Remove the broken Nix package and unused code, rename database and theme code to match what it does, and cut idle memory and the size of padded counters. Prepare 0.2.0, which drops MAYU_VERSION and the Nix package but keeps counter behaviour and stored data unchanged.

Changes

  • Remove the Nix package and its CI job. The package shipped without index.html or themes and crashed when started outside a checkout. The flake keeps a development shell for nix develop.
  • Read the homepage version from the application metadata. This removes MAYU_VERSION, the .mayu-version file, and the Docker entrypoint wrapper.
  • Keep one copy of the homepage attribution, merge duplicated styles, and remove dead styles and the media-query listener fallbacks for Safari 13 and older.
  • Rename get_counter to increment, because both counter routes increment, and move the demo rule into the request handler.
  • Rename Counter.num to count. The JSON key remains num.
  • Bind the prune thresholds as query parameters instead of building them into the SQL text.
  • Merge the cache and image modules into theme, and check the hidden-theme suffix in one function.
  • Define each repeated glyph image once per SVG and reference it with <use>. Image IDs come from a hash of the image bytes, so counters inlined into one HTML page share an ID only when their images are identical.
  • Declare the SVG encoding as UTF-8 instead of ISO-8859-1.
  • Set ERL_FLAGS="+P 262144 +Mea min" in the Docker image to shrink the process table and allocator overhead.
  • Serve /heart-beat as plain text.
  • Report startup failures once, in the panic message.
  • Rewrite the README to match current behaviour, document every route, and compare throughput, durability, memory, and image size with Moe-Counter.
  • Bump the package version to 0.2.0.

Compatibility

This change has no database migration or schema change. Databases written by 0.1.29 keep counting under 0.2.0 on SQLite and PostgreSQL, and 0.2.0 keeps the PostgreSQL integer widening from 0.1.28. Counter routes, increment semantics, name encoding, and response caching stay the same.

These changes can affect existing deployments:

  • Mayu ignores MAYU_VERSION and shows the version from gleam.toml.
  • nix run no longer works. Docker is the supported package.
  • /heart-beat returns text/plain instead of text/html. The body is still alive.
  • Setting ERL_FLAGS replaces the image's memory flags.
  • SVG markup now uses <defs> and <use>. This affects only tools that parse the SVG.

Validation

  • Formatting, compilation without warnings, all 11 Gleam regression tests, and PostgreSQL 17 integration checks passed.
  • The ARM64 container build, the HTTP smoke test with concurrent increments, the UID 1000 check, the homepage version, and the heartbeat over IPv4 and IPv6 passed.
  • The published fuwn/mayu:0.1.29 image created data on SQLite and PostgreSQL. After the upgrade, that data kept its counts, encoded names, and timestamps.
  • Chromium and WebKit 27.2 rendered inline counters identically to isolated ones. The test page showed one theme at different counts, two themes, and one counter twice.
  • Homepage element positions matched the previous version at 1280 and 400 pixel widths. The mascot still loads when a narrow window widens.
  • Benchmarks ran in Docker on one CPU with 50 concurrent connections. Idle memory fell from 72 to 45 MiB. Throughput measured 4,165 and 4,548 requests per second in two runs, against 3,908 before. At four CPUs, throughput stayed within run-to-run variation.
  • A padded counter such as 0000001 shrank from 10,550 to 3,429 bytes. A count without repeated digits grows by about 4%, and each render takes up to 0.4 microseconds longer.

Fuwn added 18 commits October 24, 2026 06:06
The compiled application already records the gleam.toml version, so the
Docker image no longer needs a version file and an entrypoint wrapper to
pass it through MAYU_VERSION.
Both routes increment, so the name now says so. The demo counter is a
request rule rather than storage behaviour.
Image header parsing had one caller, and the hidden-theme suffix was
checked separately by the picker and the default selection.
Repeated digits now reference one embedded image through <use>, which
cuts a padded counter such as 0000001 from 10,550 to 3,429 bytes. IDs come
from a hash of the image bytes, so counters inlined into one page can only
share an ID when the images are identical.
@Fuwn
Fuwn merged commit ceddfc4 into main Oct 24, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant