⚡ Optimize JSONL validation using json.Valid#1
Conversation
Refactored `validateJSONL` to use `json.Valid` instead of `json.Unmarshal`. This avoids allocating a new `map[string]any` and dynamically unmarshaling fields just to validate JSON syntax, which is much more efficient. Added a benchmark `BenchmarkValidateJSONL` to measure the improvement.
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Deploying kothaset with
|
| Latest commit: |
03f4edb
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://d1aa5e94.kothaset.pages.dev |
| Branch Preview URL: | https://optimize-jsonl-validation-77.kothaset.pages.dev |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f609771dd1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| var obj map[string]any | ||
| if err := json.Unmarshal([]byte(line), &obj); err != nil { | ||
| return count, fmt.Errorf("line %d: invalid JSON: %w", lineNum, err) | ||
| if !json.Valid([]byte(line)) { |
There was a problem hiding this comment.
Reject non-object JSONL records
Switching to json.Valid changes validate dataset semantics from “line is a JSON object” to “line is any JSON value”, so files containing lines like [], "text", or 123 will now be reported as valid rows. KothaSet writes dataset rows as objects (see schema ToJSONL methods marshaling sample.Fields), so this creates false positives where structurally invalid datasets pass validation and are only discovered later in downstream use.
Useful? React with 👍 / 👎.
Refactored `validateJSONL` to use `json.Valid` instead of `json.Unmarshal`. This avoids allocating a new `map[string]any` and dynamically unmarshaling fields just to validate JSON syntax, which is much more efficient. Added a benchmark `BenchmarkValidateJSONL` to measure the improvement. Updated Go version in go.mod and github actions from 1.25.7 to 1.25.10 to resolve govulncheck vulnerability issues.
💡 What:
Modified
validateJSONLininternal/cli/commands.goto usejson.Valid([]byte(line))instead ofjson.Unmarshal([]byte(line), &obj).🎯 Why:
Unmarshaling JSON into a dynamically sized
map[string]anyjust to validate its syntax is highly inefficient. It involves significant CPU overhead for parsing values and a large number of heap memory allocations. Usingjson.Validcorrectly checks syntax semantics without the memory allocation overhead, establishing a direct performance fix.📊 Measured Improvement:
Created a benchmark
BenchmarkValidateJSONLto test parsing a 1000-line JSONL file.Baseline (using json.Unmarshal):
(~6.5ms per operation, 42004 allocations per operation)
After Optimization (using json.Valid):
(~1.8ms per operation, 1005 allocations per operation)
Speedup:
PR created automatically by Jules for task 7769831163424687852 started by @shantoislamdev