[AI] Stroke redraw allocates and destroys a native Onyx pen for every stroke
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
- Issue type
- Refactor
- Clarity
- Mostly clear
- Activity status
- Active
- Domain
- mobile-dev, performance
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
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,NeoMarkerPenWrapperandNeoFountainPenWrappergo throughNeoPenUtils.computeStrokePoints, which doesnew NeoPenConfig()→NeoBrushPen/NeoFountainPen/NeoMarkerPen.create(config)→ … →pen.destroy()per call.NeoCharcoalPenWrapper/NeoCharcoalPenV2WrapperdoNeoCharcoalPen(V2).create(config)…pen.destroy()per call.NeoMarkerPenWrapper.drawStrokealso creates anew 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:
NeoPenhas no API to change its config after creation. Width and other parameters are fixed increate(config)/createNeoPenV2(width, …).- Each stroke is driven through
onPenDown→onPenMove→onPenUpon 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
- 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 aroundcreateNeoPenV2/create/destroy). - 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.
- 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.
- For the SDK-wrapped pens (brush, marker, charcoal) reuse would mean replacing
NeoPenUtils.computeStrokePoints/ the charcoal wrappers with our own calls against the publicNeoPenAPI. 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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Ethran/notable
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Maintainers usually reply within 1 day
-
[AI] Line tool saves raw pen pressure (clamped to full pressure)Possibly taken @kal-kaliper claimed this 1 day ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
Maintainers usually reply within 1 day
-
Editor burger menuOpenbug
Difficulty 3/5 1-2 days Newbie friendliness 55/100
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 30/100
Maintainers usually reply within 1 day
-
[Feature Suggestion] Independent Zoom Controls: Decouple Zoom-In from Zoom-Out (with 1.0x Snap)Open
Difficulty 4/5 3-5 days Newbie friendliness 48/100
Maintainers usually reply within 1 day
Similar issues
-
area:data-quality importer size:S
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
enorm-labs/event-junkie#5136 ·
Maintainers usually reply within 1 day
-
0. Needs triage bug
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
Maintainers usually reply within 1 day
-
Type: Possible bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
spacecowboy/Feeder#1318 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
wangzan101/Mika#644 ·
Maintainers usually reply within 1 day
-
good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
commons-app/apps-android-commons#7341 ·
Maintainers usually reply within 1 day