Skip to content

Change Java JSON to Avaje Jsonb#8721

Open
Gold856 wants to merge 11 commits intowpilibsuite:2027from
Gold856:avaje
Open

Change Java JSON to Avaje Jsonb#8721
Gold856 wants to merge 11 commits intowpilibsuite:2027from
Gold856:avaje

Conversation

@Gold856
Copy link
Copy Markdown
Member

@Gold856 Gold856 commented Apr 3, 2026

Jackson is a very heavy library; it supports loads of features that we don't need, and historically has caused issues due to long class loading times (a little over 2 seconds to load AprilTagFieldLayout). This often manifests as a help request in the form of "my robot disables when I do X, but doesn't disable when doing X in subsequent attempts until code restart." While SC has brought down Jackson loading times significantly, with AprilTagFieldLayout loads taking only 330 milliseconds, that's still a rather long delay, and while libraries should handle any JSON loading ahead of time to prevent delays in auto/teleop, it would still be good to make the worst case better to reduce user frustration. Benchmarks indicate using Avaje Jsonb to load AprilTagFieldLayout only takes ~70 ms, a fair chunk of which isn't actually in Avaje Jsonb (~4 ms is spent on using getResourceAsStream to retrieve the JSON file, ~8 ms is spent on just loading the AprilTag class and its dependencies).

Note that all times listed are end-to-end, meaning nothing else was done except for the operation being benchmarked, and doing arithmetic on them can be flawed due to some classes being loaded twice, i.e., getResourceAsStream and new AprilTag() likely load some of the same JDK classes and so subtracting both from the Avaje Jsonb load time is likely slightly incorrect because class loading is being double counted. For our purposes, it's likely accurate enough and is mostly just for contextualization.

Benchmarks were run on a Raspberry Pi CM5 with 2 GB of RAM. Source code for the results can be found in the "Fastjson2" commit (2456d15).

Avaje Jsonb uses code generation via annotation processors to generate the classes needed to do JSON serde and uses service providers to find them, which will require downstream changes in robot projects, as the different service providers in each library must be merged together for Avaje Jsonb to function. We will use the Gradle shadow plugin, as its already used by the installer and therefore adds zero additional dependencies.

Gold856 added 8 commits April 3, 2026 14:59
This reverts commit 6ec081a971b9e36e840cbf849d7b46fa3c71793f.
This reverts commit 883ef543f63339d3a50a67e6b55141773d46e197.
This reverts commit 867d5068c1281b79c2ac38aecc1e6f03601dbbc7.
@Gold856 Gold856 requested review from a team and PeterJohnson as code owners April 3, 2026 20:51
@github-actions github-actions bot added component: wpiutil Utility library component: wpilibj WPILib Java component: wpimath Math library component: apriltag AprilTag library 2027 2027 target labels Apr 3, 2026
@Gold856 Gold856 linked an issue Apr 3, 2026 that may be closed by this pull request
@Gold856 Gold856 force-pushed the avaje branch 2 times, most recently from 1f83229 to dcae697 Compare April 4, 2026 06:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2027 2027 target component: apriltag AprilTag library component: wpilibj WPILib Java component: wpimath Math library component: wpiutil Utility library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prefer usage of QuickBuffers over Jackson for deserializing JSON

2 participants