forked from ohler55/oj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotes
89 lines (69 loc) · 3.18 KB
/
notes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
;; -*- mode: outline; outline-regexp: " *[-\+]"; indent-tabs-mode: nil; fill-column: 120 -*-
^c^d hide subtree
^c^s show subtree
Strict Dump Performance
JSON::Ext.dump 20000 times in 0.173 seconds or 115493.546 dump/sec.
Oj:strict.dump 20000 times in 0.050 seconds or 401475.753 dump/sec.
Summary:
System time (secs) rate (ops/sec)
--------- ----------- --------------
Oj:strict 0.050 401475.753
JSON::Ext 0.173 115493.546
Comparison Matrix
(performance factor, 2.0 means row is twice as fast as column)
Oj:strict JSON::Ext
--------- --------- ---------
Oj:strict 1.00 3.48
JSON::Ext 0.29 1.00
- big decimal
- just in custom mode, maybe in strict?
- encode_big_decimal_as_string
- add as fix for rails change
- rails
- Process::Status
- ActiveSupport::TimeWithZone
- ActiveModel::Errors
- ActiveSupport::Multibyte::Chars
- ActiveRecord::Relation
- debug
- instrument for parsing floats/bigdecimal
- branch
- option to allow invalid unicode through
- unit tests for 32 bit - test_float_parse
- look at RUBY_PLATFORM maybe?
- look at env var for OJ_DEBUG when doing ruby extconf.rb
- add printf for keys spots in parse and dump
- invalid character option
- don't check options
- replace with best attempt such as \ud83d => \xED\xA0\xBD
- that would be the normal replacement
- allow_invalid_unicode
- streaming parser for scp and saj
---------------------------
Tried a separate thread for the parser and the results were poor. The parsing is
10% to 15% of the total so splitting ruby calls and c does not help much and the
overhead of swapping data was too high. It was not possible to split ruby calls
into both threads due to not getting a lock on the ruby environment for object
creation.
----------------
todo
- #570 - complain in strict mode about leading + or trailing .
- #569 - < and > are not escaped in compat mode
- ruby -r oj -e 'puts "#{Oj::VERSION} -> #{Oj.dump("<", {mode: :compat, escape_mode: :unicode_xss})}"'
3.7.5 -> "<"
3.7.4 -> "\u003c"
- #568 - We're still at Rails 4.2 so maybe all of this is outdated, but still.
It's documented that :bigdecimal_as_decimal isn't available for mode: :rails. However, if I run it like this:
Oj.optimize_rails
Oj.default_options = { mode: :rails, bigdecimal_as_decimal: true }
It does the job - Oj dumps BigDecimal as number.
If I later add bigdecimal_as_decimal: true explicitely in the dump it works for single number dump, but not for Hash.
Oj.dump(BigDecimal('1.2')) # => "1.2"
Oj.dump({a: BigDecimal('1.2')}) # => "{\"a\":1.2}"
Oj.dump(BigDecimal('1.2'), bigdecimal_as_decimal: true) # => "1.2"
Oj.dump({a: BigDecimal('1.2')}, bigdecimal_as_decimal: true) # => "{\"a\":\"1.2\"}" - unexpected
Also when I remove running Oj.optimize_rails, Oj ignores bigdecimal_as_decimal and dumps BigDecimal as string.
Currently, it works OK for me, just wanted to check what's the expected behavior and if it should be aware when upgrading Rails or Oj.
- #567 - irb(main):001:0> Oj.dump(Time.utc(2000, 1, 1, 1, 0, 0, 0), mode: :compat)
=> "\"2000-01-01 01:00:00 UTC\""
- missing fractional part in custom with second_precision id 0 fraction