aconchillo / guile-json

JSON module for Guile
GNU General Public License v3.0
100 stars 34 forks source link

support for handling duplicate keys #86

Closed aconchillo closed 9 months ago

aconchillo commented 9 months ago

This patch adds support for handling duplicate keys. If a duplicate key is found in an object the last value will be used. If #ordered is used, the first appearance of the key is considered in the order.

Fixes #84

aconchillo commented 9 months ago

Performance with this change is affected a bit with large files because of having to create new hash tables and add items to it:

With this patch:

scheme@(guile-user)> ,t (->bool (call-with-input-file "large-file.json" (lambda (port) (json->scm port))))
$7 = #t
;; 1.364272s real time, 2.084502s run time.  0.823799s spent in GC.

With current behavior:

scheme@(guile-user)> ,t (->bool (call-with-input-file "large-file.json" (lambda (port) (json->scm port))))
$4 = #t
;; 1.262949s real time, 2.199526s run time.  1.057755s spent in GC.
aconchillo commented 9 months ago

Closing in favor of #85 since it's more performant. If in the future there's a performant issue we might consider this one, but I think it should be good for now.