[AI] Stroke redraw allocates and destroys a native Onyx pen for every stroke

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

Maintainers usually reply within 1 day

@kal-kaliper is already working on this.

Since Nov 14, 2026.

  • #391 by @kal-kaliper — open

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Active
Tech stack
android, kotlin

Research direction

Start by tracing PageView.drawAreaScreenCoordinates or drawOnCanvasFromPage and measure a full-page redraw on a real device, separating native pen creation and destruction from rendering. If that cost is significant, prototype reuse for the fountain V2 and square wrappers in editor/drawing/onyx/ and compare output against fresh pens. Done means the measurements justify the change and visual checks show no stroke differences.

Written by the indexing model from the issue text.

Description

enhancement

Summary

When a page is (re)drawn, every stroke drawn with a Neo pen allocates a new native Onyx pen, renders one stroke with it, and destroys it. On a page with thousands of strokes that is thousands of JNI allocate/free round-trips per redraw (page open, scroll, zoom, undo, erase repaint). This may be a significant part of redraw time and needs to be measured.

Where it happens

Notable's own wrappers (editor/drawing/onyx/):

  • NeoFountainPenV2Wrapper.drawStroke: FountainShapes.createNeoPenV2(...) → NeoPenRender(neoPen) → render(...) → destroyPen(), once per stroke.
  • NeoSquarePenWrapper.drawStroke: NeoSquarePen.create(config) → NeoPenRender → destroyPen(), once per stroke.

Onyx SDK wrappers that OnyxStrokeRenderer calls (confirmed in the onyxsdk-pen 1.5.8 sources, which Onyx now publishes as -sources.jar):

  • NeoBrushPenWrapper, NeoMarkerPenWrapper and NeoFountainPenWrapper go through NeoPenUtils.computeStrokePoints, which does new NeoPenConfig() → NeoBrushPen/NeoFountainPen/NeoMarkerPen.create(config) → … → pen.destroy() per call.
  • NeoCharcoalPenWrapper / NeoCharcoalPenV2Wrapper do NeoCharcoalPen(V2).create(config) … pen.destroy() per call.
  • NeoMarkerPenWrapper.drawStroke also creates a new Canvas(...) over the shared screen-sized pen bitmap per stroke (see #309 for the related offscreen-buffer issue).

Only the ballpoint pen is rendered without a native pen.

Why reuse might be possible

From the onyxsdk-penbrush 1.1.2 sources:

  • NeoPen has no API to change its config after creation. Width and other parameters are fixed in create(config) / createNeoPenV2(width, …).
  • Each stroke is driven through onPenDown → onPenMove → onPenUp on the native handle (NeoPenNative.onPenDown(penHandle, …)), which looks like a per-stroke state machine. So one native pen per (pen type, width, other config) could probably be reused for many strokes within one redraw pass and destroyed once at the end.

Not verified: that onPenDown fully resets the native state (no carry-over of smoothing or prediction from the previous stroke), and that NeoPenRender can be reused or recreated cheaply around a reused NeoPen.

What to investigate

  1. Measure first. Time a full-page redraw on a stroke-heavy page (e.g. PageView.drawAreaScreenCoordinates / drawOnCanvasFromPage) on a real device (Note Air 4C / Note 4C). Split the time into pen create/destroy and the actual render (method tracing or manual timers around createNeoPenV2 / create / destroy).
  2. If create/destroy is significant, prototype a per-redraw pen cache for the pens we construct ourselves (fountain V2, square): key by pen type + config (width, …), reuse across strokes, destroy all at the end of the pass.
  3. Verify visually that reused pens produce identical output to fresh ones (overlay or pixel diff of a test page), especially for the fountain V2 smoothing and the first/last segments of each stroke.
  4. For the SDK-wrapped pens (brush, marker, charcoal) reuse would mean replacing NeoPenUtils.computeStrokePoints / the charcoal wrappers with our own calls against the public NeoPen API. Worth doing only if step 1 shows a real gain.

Context

Found while reviewing the Onyx SDK 1.5.8 / penbrush 1.1.2 sources during the SDK bump (notes in docs/onyx-sdk/sdk-release-changelog.md, untracked working docs).

Dominant language
Kotlin
Stars
269
Forks
44
Avg merge
1d 17h
Merged PRs (30d)
22

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

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 Ethran/notable

All issues in Ethran/notable

Similar issues

More Kotlin issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.