valyala/fastjson là một trong những repo phía máy chủ mà TopGit theo dõi, hiện có 2.5k sao, viết chủ yếu bằng Go. Fast JSON parser and validator for Go. No custom structs, no code generation, no reflection
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
Fast. As usual, up to 15x faster than the standard encoding/json.
See benchmarks.
Parses arbitrary JSON without schema, reflection, struct magic and code generation
contrary to easyjson.
Provides simple API.
Outperforms jsonparser and gjson
when accessing multiple unrelated fields, since fastjson parses the input JSON only once.
Validates the parsed JSON unlike jsonparser
and gjson.
May quickly extract a part of the original JSON with Value.Get(...).MarshalTo and modify it
with Del
and Set functions.
May parse array containing values with distinct types (aka non-homogenous types).
For instance, fastjson easily parses the following JSON array [123, "foo", [456], {"k": "v"}, null].
fastjson preserves the original order of object items when calling
Object.Visit.
Known limitations
Requies extra care to work with - references to certain objects recursively
returned by Parser
must be released before the next call to Parse.
Otherwise the program may work improperly. The same applies to objects returned by Arena.
Adhere recommendations from docs.
Cannot parse JSON from io.Reader. There is Scanner
for parsing stream of JSON values from a string.
fastjson shouldn't crash or panic when parsing input strings specially crafted
by an attacker. It must return error on invalid input JSON.
fastjson requires up to sizeof(Value) * len(inputJSON) bytes of memory
for parsing inputJSON string. Limit the maximum size of the inputJSON
before parsing it in order to limit the maximum memory usage.
Performance optimization tips
Re-use Parser and Scanner
for parsing many JSONs. This reduces memory allocations overhead.
ParserPool may be useful in this case.
Prefer calling Value.Get* on the value returned from Parser
instead of calling Get* one-liners when multiple fields
must be obtained from JSON, since each Get* one-liner re-parses
the input JSON again.
Prefer calling once Value.Get
for common prefix paths and then calling Value.Get* on the returned value
for distinct suffix paths.
Prefer iterating over array returned from Value.GetArray
with a range loop instead of calling Value.Get* for each array item.
Fuzzing
Install go-fuzz & optionally the go-fuzz-corpus.
go get -u github.com/dvyukov/go-fuzz/go-fuzz github.com/dvyukov/go-fuzz/go-fuzz-build
Build using go-fuzz-build and run go-fuzz with an optional corpus.
stdjson-map - parse into a map[string]interface{} using encoding/json.
stdjson-struct - parse into a struct containing
a subset of fields of the parsed JSON, using encoding/json.
stdjson-empty-struct - parse into an empty struct using encoding/json.
This is the fastest possible solution for encoding/json, may be used
for json validation. See also benchmark results for json validation.
fastjson - parse using fastjson without fields access.
fastjson-get - parse using fastjson with fields access similar to stdjson-struct.
Q: There are a ton of other high-perf packages for JSON parsing in Go. Why creating yet another package?
A: Because other packages require either rigid JSON schema via struct magic
and code generation or perform poorly when multiple unrelated fields
must be obtained from the parsed JSON.
Additionally, fastjson provides nicer API.
Q: What is the main purpose for fastjson?
A: High-perf JSON parsing for RTB
and other JSON-RPC services.
Q: Why fastjson doesn't provide fast marshaling (serialization)?
A: Actually it provides some sort of marshaling - see Value.MarshalTo.
But I'd recommend using quicktemplate
for high-performance JSON marshaling :)
Q: fastjson crashes my program!
A: There is high probability of improper use.
Make sure you don't hold references to objects recursively returned by Parser / Scanner
beyond the next Parser.Parse / Scanner.Next call
if such restriction is mentioned in docs.
Make sure you don't access fastjson objects from concurrently running goroutines
if such restriction is mentioned in docs.
Build and run your program with -race flag.
Make sure the race detector detects zero races.
If your program continue crashing after fixing issues mentioned above, file a bug.
valyala/fastjson thuộc nhóm Backend trên TopGit, cùng 6 topic GitHub. Trang Trending và Topics liệt kê các repo cùng số sao và cùng ngôn ngữ để so sánh.
Đọc thêm về valyala/fastjson ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/valyala/fastjson là nguồn chính thức.
valyala/fastjson có bao nhiêu sao?
valyala/fastjson có 2.5k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/valyala/fastjson. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
valyala/fastjson có những chủ đề gì?
GitHub topics của valyala/fastjson: "fast", "go", "golang", "json", "json-parser", "json-validation". TopGit xếp repo vào nhóm Backend.
valyala/fastjson có phải mã nguồn mở không?
Có — valyala/fastjson phát hành theo license MIT, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/valyala/fastjson.
valyala/fastjson có website riêng không?
TopGit chưa ghi nhận URL trang chủ cho valyala/fastjson. Phần README ở tab phía trên thường có link demo, hoặc xem mô tả GitHub của repo.
valyala/fastjson còn đang phát triển không?
Commit gần nhất trên valyala/fastjson là 5 tháng trước (theo timestamp GitHub). Repo có 158 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
Đọc đầy đủ README ở tab phía trên.
Muốn nghe thêm một ý kiến về fastjson?
Hỏi một AI đọc được trang này — một cú bấm là có ngay nhận định về fastjson.