Skip to content

Rewrite util.TableToJSON to match GMod output - #269

Closed
spacevx wants to merge 2 commits into
SourceDotNET:mainfrom
spacevx:refactor/table-to-json
Closed

spacevx wants to merge 2 commits into
SourceDotNET:mainfrom
spacevx:refactor/table-to-json

Conversation

@spacevx

@spacevx spacevx commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Rewrites util.TableToJSON to match Garry's Mod one, but writes JSON directly instead of building a Bootil::Data::Tree first like GMod does, as suggested in Facepunch/garrysmod-requests#2822

Fixes

  • Integers were written as 5.0 instead of 5
  • Number keys didn't use Lua's tostring, bool keys were dropped, and inf / NaN were written as 0 instead of null
  • {[""] = x} gave {"": x} instead of [x]
  • And probably other fixes

Benchmarks

Case GMod (ms) SDN (ms)
1M strings 427.5 49.1
1M ints 467.6 53.8
1M doubles 825.1 195.9
200k small objects 436.3 90.3
1000×1000 ints 414.8 52.7
200k vectors 174.6 28.7
200k objects, pretty 405.5 104.9
10M strings (from the issue) 4285.5 500.9
1500-deep table 0.54 0.17

(Benchmark was done on a Ryzen 9 9950x on W11, if you want me to give the code used for the benchmark don't hesitate)

@marchc1

marchc1 commented Nov 16, 2026

Copy link
Copy Markdown
Member

While I want to do this, we probably should hold off on deviations until we have the API solid. I will absolutely accept and review this though in the future

@spacevx

spacevx commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

While I want to do this, we probably should hold off on deviations until we have the API solid. I will absolutely accept and review this though in the future

No problem i think we can just let it open, unless you want me to do another one for the fixes

@spacevx
spacevx marked this pull request as draft November 16, 2026 22:28
@marchc1

marchc1 commented Nov 17, 2026

Copy link
Copy Markdown
Member

I would say probably should close it but save the branch for later (don't want these piling up too much, and it will probably be a while)

@spacevx spacevx closed this Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants