Chuyển đến nội dung
Skillpedia
Ứng dụng di động8.7k · #12333

nuke-optimize

Skill này làm gì

Skill này tìm nguyên nhân khiến việc tải ảnh chậm hoặc tốn bộ nhớ trong app dùng thư viện Nuke. Nó dành cho lập trình viên iPhone và Mac muốn các màn hình ảnh mượt hơn.

Khi nào nên dùng

  • ✓Khi ảnh trong app của bạn tải chậm hoặc bộ nhớ đệm liên tục bị trượt.
  • ✓Khi việc cuộn bị giật trên một màn hình hiển thị nhiều ảnh.
  • ✓Khi bộ nhớ của app tăng liên tục vì ảnh.

Liên kết skill

https://github.com/kean/Nuke/blob/main/skills/nuke-optimize/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/kean/Nuke/blob/main/skills/nuke-optimize/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Danh sách ảnh của chúng tôi bị giật khi cuộn và dùng quá nhiều bộ nhớ. Tìm nguyên nhân và sửa cấu hình Nuke.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Skill bật log chẩn đoán của Nuke, đọc mỗi dòng cho một tác vụ ảnh để xem thời gian đi đâu, rồi thay đổi từng thứ một và đo lại.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Optimizing Nuke

Nuke's defaults come from benchmarks, so the gains are almost always in how the app asks for images, and rarely in its configuration. A 12 MP photo decoded for a 120-point cell costs 46 MB, and no setting makes up for that.

Measure first, change one thing, and measure again. Each change here has a cost, and some make things worse when the cause is something else. If you can't run the app, say that what you changed comes from reading the code, and that it's unmeasured. For the API in general, see llms-full.txt at the root of the package.

Measure

Launch with NUKE_DIAGNOSTICS_LOG=1, in the scheme or like this, and read one line per task:

SIMCTL_CHILD_NUKE_DIAGNOSTICS_LOG=1 xcrun simctl launch booted <bundle-id>
xcrun simctl spawn booted log stream --predicate 'subsystem == "com.github.kean.Nuke.ImagePipeline"'
ImageTask #1 · success · 78.5 ms · from network · https://example.com/a.png · 1200×800 · png · 3.7 MB in memory · 70 KB

Go through the slow screen twice: once on a fresh install, and again after relaunching.

In the log It means Go to
from network after a relaunch The disk cache missed Cache keys, Disk cache
from httpCache, and tens of ms URLCache asked the server whether the image changed Disk cache
MB in memory over width × height × 4 of the cell, in pixels The image is bigger than what's displayed Decode less
The same URL twice, with no coalesced Two requests that differ, so nothing is shared Cache keys, Prefetching
More lines than cells on screen, on open Everything loads at once Load only what's on screen
A long list of cancelled Normal while scrolling fast: the cells cancel the loads they scrolled past Nothing

For where the time of a slow task went:

let pipeline = ImagePipeline { $0.isDiagnosticsEnabled = true }
let task = pipeline.imageTask(with: url)
_ = try await task.image
print(task.metrics!.formatted([.header, .breakdown]))
time:  network 93.6 ms (66%) · process 42.5 ms (30%) · cache 0.5 ms · decode 0.3 ms · queue 0.1 ms · other 3.8 ms (3%)
Largest share Cause
network The file is too big, it wasn't cached, or the app opened a new connection
process, decode, decompress The image is bigger than it needs to be
queue The task waited for a slot. Prefetching, or too many images at once

isDiagnosticsEnabled costs a few microseconds a task, and it sends signposts, so the same stages show up in Instruments under os_signpost. For a task that hangs, po ImagePipeline.shared.diagnostics in the debugger prints the queues and the memory cache.

Read the code

# More than one pipeline, or one created in a view
grep -rnE 'ImagePipeline(\(| \{)' --include='*.swift' .
# Every image load: does each one know the size it's displayed at?
grep -rnE 'LazyImage\(|ImageLoader\.load|FetchImage\(|\.image\(for:|imageTask\(with:' --include='*.swift' .
# Disk I/O that blocks the caller, which is a problem on the main thread
grep -rnE 'cachedData\(|cachedImage\(|containsCachedImage|containsData\(|storeCachedImage' --include='*.swift' .
# Prefetchers, and whether they build the same request as the views
grep -rn 'ImagePrefetcher' --include='*.swift' .
# Defaults someone changed: find out why before you keep or remove them
grep -rnE 'isTaskCoalescingEnabled|isDecompressionEnabled|skipDecompression|isProgressiveDecodingEnabled|isResumableDataEnabled|TaskQueue\(|maxConcurrentTaskCount|costLimit|sizeLimit' --include='*.swift' .
# Processors of your own: is the identifier stable?
grep -rnE ': ImageProcessing\b' --include='*.swift' .

What to fix, in the order it pays

Download less

The cheapest image is the one the server resizes. If the CDN takes a size, as in ?w=360, ask for the size you display. That saves the data, the decode, and the memory, and nothing below does all three.

A decoded image has a scale of 1, so a 360-pixel file is 360 points wide. If the view shows it at its natural size, or a processor of yours draws in points, set request.scale to the scale of the screen.

Decode less

Tell the pipeline the size you display at, in the request or with .processors. A SwiftUI .frame doesn't: it scales a full-size bitmap on every draw.

LazyImage(url: url) { state in
  
Câu hỏi thường gặp

Nó đo tốc độ bằng cách nào?

Nó dùng log chẩn đoán của Nuke, in một dòng cho mỗi tác vụ ảnh với thời gian và nguồn của nó.

Nếu tôi không chạy được app thì sao?

Skill yêu cầu ghi nhãn các thay đổi là dựa trên việc đọc code, chưa được đo lường.

Nó có hỗ trợ các phiên bản Nuke cũ không?

Có. Nó hỗ trợ Nuke 14 và ghi chú những điểm khác biệt trên phiên bản 13.

Chi tiết

Mô tả gốc của tác giả

Find out why images load slowly, scrolling stutters, memory grows, or the cache misses in an app that uses Nuke, and fix it. Use when asked to make images faster, to use less memory or data, to review how an app sets up Nuke, or to tune ImagePipeline, ImageCache, DataCache, ImagePrefetcher, or LazyImage. Covers Nuke 14, and what differs on 13.

repo: kean/Nuke

Độ phổ biến

Sao GitHub
8.7k
Vị trí xếp hạng
#12333
Giấy phép
MIT
Cập nhật
2/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự