Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Consider removing un-needed memory operation shims

Open
#44 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
50/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Quiet
Tech stack
c, wasm

Research direction

Start with src/mem.c and mem.h, then audit the current call sites in input_init and buf_put against the -O2 -mbulk-memory --gc-sections build. Compare raw and gzipped clayterm.wasm sizes with main using wc -c and gzip -c | wc -c. Done means each shim has a documented keep-or-remove decision, with the build and size measurements supporting it.

Written by the indexing model from the issue text.

Description

src/mem.c currently provides memcpy, memset, strlen, and align8 as freestanding-wasm shims, and PR #32 proposes adding a memmove shim alongside them. Investigation of the linked clayterm.wasm shows that none of these functions survive into the final binary under the current -O2 -mbulk-memory --gc-sections build:

  • A non-stripped build links cleanly with zero memcpy/memset/strlen/align8 symbols in the output.
  • input_init — the heaviest caller, containing the trie-building loop over the static cap tables — compiles to zero call instructions. LLVM inlines every constant-size memset/memcpy, unrolls the trie loop, and constant-folds strlen on the literal sequences.
  • buf_put's variable-length memcpy lowers directly to a memory.copy instruction thanks to -mbulk-memory.

In other words, the shims exist purely as a safety net for code the optimizer fails to lower. And if the optimizer fails to lower it, then that is something that should be surfaced, not silently cause our performance to degrade.

Possible Approach

Audit each shim against current call sites and decide case-by-case:

  • align8 — trivial (n + 7) & ~7. Best candidate for a free win: move into mem.h as static inline and drop the definition from mem.c. Before doing so, build and compare raw + gzipped bundle size against main to confirm the inline expansion does not regress size (it shouldn't — every call site is already inlined — but it is worth measuring rather than assuming).
  • memset / memcpy — every current call is constant-size or variable-length-with--mbulk-memory-lowering, so both are dead in the linked binary. Keep as a safety net or drop entirely; if dropped, document the requirement that contributors avoid call patterns the optimizer cannot lower.
  • strlen — only foldable because the cap tables are statically initialized literals. A future call on a runtime string (e.g. buf_str(b, user_input)) would re-introduce the link dependency. Lowest-risk shim to keep.
  • memmove (PR #32) — reconsider in light of the above. If we keep the others as defensive shims, merging this one is consistent; if we trim, this one should not land without a real call site.

Decisions should be backed by before/after wc -c and gzip -c | wc -c on clayterm.wasm.

Dominant language
TypeScript
Stars
42
Forks
2
Avg merge
2d 5h
Merged PRs (30d)
12

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from bombshell-dev/tty

All issues in bombshell-dev/tty

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.