-
Notifications
You must be signed in to change notification settings - Fork 0
docs: fix install instructions and qualify ARM64 performance claims #58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
de38f67
docs: fix install instructions and qualify ARM64 performance claims
membphis 423f463
docs: revert install section — luarocks install lua-qjson is published
membphis b959aec
docs: add ARM64 NEON benchmark data and script (Apple M4)
membphis f61520b
docs: address Copilot review on PR #58
membphis 2660a4b
docs: drop irrelevant rationale for omitting simdjson on ARM64
membphis 31a6c75
docs: unify simdjson-omission wording in benchmarks.md
membphis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| -- ARM64 NEON benchmark: qjson vs lua-cjson (parse + access only) | ||
| -- Run from worktree root: | ||
| -- LUA_PATH='./lua/?.lua;;' DYLD_LIBRARY_PATH=./target/release \ | ||
| -- luajit benches/arm_bench.lua | ||
| -- | ||
| -- qjson loads its native lib via `ffi.load` (honors DYLD_LIBRARY_PATH / | ||
| -- LD_LIBRARY_PATH), so only cjson needs a package.cpath entry below. | ||
|
|
||
| package.cpath = "./vendor/lua-cjson/?.so;" .. package.cpath | ||
|
|
||
| local qjson = require("qjson") | ||
| local cjson = require("cjson") | ||
| local function make_b64_block() | ||
| local b64_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" | ||
| local rng = 12345 | ||
| local t = {} | ||
| for i = 1, 64 * 1024 do | ||
| rng = (rng * 48271) % 2147483647 | ||
| local idx = (rng % 64) + 1 | ||
| t[i] = b64_chars:sub(idx, idx) | ||
| end | ||
| return table.concat(t) | ||
| end | ||
|
|
||
| local B64_BLOCK = make_b64_block() | ||
| local B64_BLOCK_LEN = #B64_BLOCK | ||
|
|
||
| local function make_b64(size) | ||
| if size <= B64_BLOCK_LEN then | ||
| return B64_BLOCK:sub(1, size) | ||
| end | ||
| local reps = math.ceil(size / B64_BLOCK_LEN) | ||
| return string.rep(B64_BLOCK, reps):sub(1, size) | ||
| end | ||
|
|
||
| local function make_payload(target_bytes) | ||
| local message_count = math.max(1, math.ceil(target_bytes / (1024 * 1024))) | ||
| local envelope = '{"model":"gpt-4-vision","temperature":0.7,"messages":[]}' | ||
| local text = string.rep("Q", 256) | ||
| local text_part = '{"type":"text","text":"' .. text .. '"}' | ||
| local image_prefix = '{"type":"image_url","image_url":{"url":"data:image/jpeg;base64,' | ||
| local image_suffix = '"}}' | ||
| local message_overhead = #('{"role":"user","content":[,]}') + #text_part | ||
| + #image_prefix + #image_suffix | ||
| local remaining = target_bytes - #envelope - (message_count * message_overhead) | ||
| local image_size = math.max(1024, math.floor(remaining / message_count)) | ||
|
|
||
| local messages = {} | ||
| for i = 1, message_count do | ||
| local role = i % 2 == 1 and "user" or "assistant" | ||
| local b64 = make_b64(image_size) | ||
| local image_part = image_prefix .. b64 .. image_suffix | ||
| messages[i] = '{"role":"' .. role .. '","content":[' | ||
| .. text_part .. "," .. image_part .. ']}' | ||
| end | ||
|
|
||
| return '{"model":"gpt-4-vision","temperature":0.7,"messages":[' | ||
| .. table.concat(messages, ",") .. ']}' | ||
| end | ||
|
|
||
| local ROUNDS = 5 | ||
|
|
||
| local function bench(name, iters, fn) | ||
| local warmup = math.max(50, math.floor(iters / 5)) | ||
| for _ = 1, warmup do fn() end | ||
|
|
||
| collectgarbage("collect") | ||
|
|
||
| local ops = {} | ||
| for r = 1, ROUNDS do | ||
| local t0 = os.clock() | ||
| for _ = 1, iters do fn() end | ||
| local t1 = os.clock() | ||
| ops[r] = iters / (t1 - t0) | ||
| end | ||
|
|
||
| table.sort(ops) | ||
| return ops[math.ceil(ROUNDS / 2)] | ||
| end | ||
|
|
||
| local content_paths_cache = {} | ||
|
|
||
| local function content_paths(n) | ||
| local paths = content_paths_cache[n] | ||
| if paths then return paths end | ||
| paths = {} | ||
| for i = 0, n - 1 do | ||
| paths[i + 1] = "messages[" .. i .. "].content" | ||
| end | ||
| content_paths_cache[n] = paths | ||
| return paths | ||
| end | ||
|
|
||
| local scenarios = { | ||
| {name = "small", target = 2 * 1024, iters = 5000}, | ||
| {name = "medium", target = 60 * 1024, iters = 500}, | ||
| {name = "100k", target = 100 * 1024, iters = 200}, | ||
| {name = "1m", target = 1024 * 1024, iters = 50}, | ||
| {name = "10m", target = 10 * 1024 * 1024, iters = 5}, | ||
| } | ||
|
|
||
| io.write("Generating payloads...") | ||
| io.flush() | ||
| local payloads = {} | ||
| for _, s in ipairs(scenarios) do | ||
| payloads[s.name] = make_payload(s.target) | ||
| io.write(" " .. s.name) | ||
| io.flush() | ||
| end | ||
| print(" done.") | ||
| print("") | ||
|
|
||
| local header_fmt = "%-10s %-10s %-12s %-12s %-10s" | ||
| print(string.format(header_fmt, "Scenario", "Size", "cjson", "qjson.parse", "speedup")) | ||
| print(string.rep("-", 58)) | ||
|
|
||
| for _, s in ipairs(scenarios) do | ||
| local payload = payloads[s.name] | ||
| local size_kb = #payload / 1024 | ||
| local size_label | ||
| if size_kb >= 1024 then | ||
| size_label = string.format("%.1f MB", size_kb / 1024) | ||
| else | ||
| size_label = string.format("%.0f KB", size_kb) | ||
| end | ||
|
|
||
| local cjson_ops = bench("cjson " .. s.name, s.iters, function() | ||
| local obj = cjson.decode(payload) | ||
| local _ = obj.model | ||
| local _ = obj.temperature | ||
| if obj.messages then | ||
| for _, msg in ipairs(obj.messages) do | ||
| local _ = msg.content | ||
| end | ||
| end | ||
| end) | ||
|
|
||
| local qjson_ops = bench("qjson " .. s.name, s.iters, function() | ||
| local doc = qjson.parse(payload) | ||
| local _ = doc:get_str("model") | ||
| local _ = doc:get_f64("temperature") | ||
| local n = doc:len("messages") or 0 | ||
| local paths = content_paths(n) | ||
| for i = 1, n do | ||
| local _ = doc:typeof(paths[i]) | ||
| end | ||
| end) | ||
|
|
||
| local speedup = qjson_ops / cjson_ops | ||
| print(string.format("%-10s %-10s %-12.0f %-12.0f %-10.1fx", | ||
| s.name, size_label, cjson_ops, qjson_ops, speedup)) | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix ordered-list indentation to satisfy markdownlint (MD005).
Line 234 and Line 238 are indented one space more than other top-level list items; this triggers the lint warning and can cause inconsistent rendering.
Suggested fix
📝 Committable suggestion
🧰 Tools
🪛 markdownlint-cli2 (0.22.1)
[warning] 234-234: Inconsistent indentation for list items at the same level
Expected: 0; Actual: 1
(MD005, list-indent)
[warning] 238-238: Inconsistent indentation for list items at the same level
Expected: 0; Actual: 1
(MD005, list-indent)
🤖 Prompt for AI Agents