-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Describe the feature
Currently it uses Object.defineProperty
to attach format info to the parsed object. How about using WeakMap
to store/retrieve formats stored in a seperate global variable?
const formats = new WeakMap<any, FormatInfo>();
{
// store
formats.set(obj, format)
}
{
// retrieve
formats.get(obj)
}
Benifits:
- It avoids "polluting" the parsed object with an extra symbol preperty.
- It's slightly faster:
benchmark avg (min … max) p75 / p99 (min … top 1%)
-------------------------------------------- -------------------------------
confbox.parseJSONC 7.91 µs/iter 7.58 µs █
(7.42 µs … 963.21 µs) 11.63 µs █
(592.00 b … 223.95 kb) 7.95 kb ▃█▃▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁
confbox.parseJSONCWithWeakMap 7.62 µs/iter 7.63 µs █
(7.60 µs … 7.65 µs) 7.64 µs ██ █ █ █
(Infinity pb … -Infinity b) NaN ██▁██▁▁█▁██▁████▁▁▁▁█
summary
confbox.parseJSONCWithWeakMap
1.05x faster than confbox.parseJSONC
Additional information
- Would you be willing to help implement this feature?
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request