msgpack 1.5.2 → 1.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ChangeLog +10 -0
- data/README.md +3 -1
- data/bench/bench.rb +78 -0
- data/ext/msgpack/buffer.c +5 -36
- data/ext/msgpack/buffer.h +9 -1
- data/ext/msgpack/buffer_class.c +6 -6
- data/ext/msgpack/compat.h +0 -99
- data/ext/msgpack/extconf.rb +9 -11
- data/ext/msgpack/packer.c +0 -24
- data/ext/msgpack/packer.h +1 -7
- data/ext/msgpack/packer_class.c +1 -1
- data/ext/msgpack/unpacker.c +15 -26
- data/ext/msgpack/unpacker_class.c +2 -3
- data/lib/msgpack/version.rb +1 -1
- data/msgpack.gemspec +1 -0
- data/spec/factory_spec.rb +4 -0
- data/spec/spec_helper.rb +5 -1
- data/spec/unpacker_spec.rb +12 -0
- metadata +18 -13
- data/bench/pack.rb +0 -23
- data/bench/pack_log.rb +0 -33
- data/bench/pack_log_long.rb +0 -65
- data/bench/pack_symbols.rb +0 -28
- data/bench/run.sh +0 -14
- data/bench/run_long.sh +0 -35
- data/bench/run_symbols.sh +0 -26
- data/bench/unpack.rb +0 -21
- data/bench/unpack_log.rb +0 -34
- data/bench/unpack_log_long.rb +0 -67
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec6ef147d4d948d86915dd5ed06893bd281bcba60a1a48869e0f1b895e1a4d7e
|
4
|
+
data.tar.gz: 49f4753d9ce5fc686c529a97b8fb409283cde4521c8e28a3f61d92fedc717148
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b094e3408d3d7411af91e81e3e59dfb23875696d2415b8759fa9d11476de795a98d7a2d1b9eee60a603157a3139614e5a349169c75d3737faabacbf4975bc31d
|
7
|
+
data.tar.gz: 27e8b222d6a20253b341e3dc5fe1f656e2698af47e95d2e1c40abb43c22a26c231cc680519e7464ba9b45745cd550f9a7ab649015311c69468f93944fd9dfc6a
|
data/ChangeLog
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
2022-07-25
|
2
|
+
|
3
|
+
* Fix a segfault when deserializing empty symbol (`:""`).
|
4
|
+
* Improve compilation flags to not strip debug symbols.
|
5
|
+
|
6
|
+
2022-05-30 version 1.5.3:
|
7
|
+
|
8
|
+
* Fix deduplication of empty strings when using the `freeze: true` option.
|
9
|
+
* Use `rb_hash_new_capa` when available (Ruby 3.2) for improved performance when parsing large hashes.
|
10
|
+
|
1
11
|
2022-05-27 version 1.5.2:
|
2
12
|
|
3
13
|
* Fix bug about unpacking ext type objects with the recursive option
|
data/README.md
CHANGED
@@ -40,7 +40,7 @@ or build msgpack-ruby and install:
|
|
40
40
|
MessagePack for Ruby should run on x86, ARM, PowerPC, SPARC and other CPU architectures.
|
41
41
|
|
42
42
|
And it works with MRI (CRuby) and Rubinius.
|
43
|
-
Patches to improve portability
|
43
|
+
Patches to improve portability are highly welcomed.
|
44
44
|
|
45
45
|
|
46
46
|
## Serializing objects
|
@@ -51,6 +51,7 @@ Use `MessagePack.pack` or `to_msgpack`:
|
|
51
51
|
require 'msgpack'
|
52
52
|
msg = MessagePack.pack(obj) # or
|
53
53
|
msg = obj.to_msgpack
|
54
|
+
File.binwrite('mydata.msgpack', msg)
|
54
55
|
```
|
55
56
|
|
56
57
|
### Streaming serialization
|
@@ -71,6 +72,7 @@ Use `MessagePack.unpack`:
|
|
71
72
|
|
72
73
|
```ruby
|
73
74
|
require 'msgpack'
|
75
|
+
msg = File.binread('mydata.msgpack')
|
74
76
|
obj = MessagePack.unpack(msg)
|
75
77
|
```
|
76
78
|
|
data/bench/bench.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# % bundle install
|
2
|
+
# % bundle exec ruby bench/bench.rb
|
3
|
+
|
4
|
+
require 'msgpack'
|
5
|
+
|
6
|
+
require 'benchmark/ips'
|
7
|
+
|
8
|
+
object_plain = {
|
9
|
+
'message' => '127.0.0.1 - - [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326 "http://www.example.com/start.html" "Mozilla/4.08 [en] (Win98; I ;Nav)"'
|
10
|
+
}
|
11
|
+
|
12
|
+
data_plain = MessagePack.pack(object_plain)
|
13
|
+
|
14
|
+
object_structured = {
|
15
|
+
'remote_host' => '127.0.0.1',
|
16
|
+
'remote_user' => '-',
|
17
|
+
'date' => '10/Oct/2000:13:55:36 -0700',
|
18
|
+
'request' => 'GET /apache_pb.gif HTTP/1.0',
|
19
|
+
'method' => 'GET',
|
20
|
+
'path' => '/apache_pb.gif',
|
21
|
+
'protocol' => 'HTTP/1.0',
|
22
|
+
'status' => 200,
|
23
|
+
'bytes' => 2326,
|
24
|
+
'referer' => 'http://www.example.com/start.html',
|
25
|
+
'agent' => 'Mozilla/4.08 [en] (Win98; I ;Nav)',
|
26
|
+
}
|
27
|
+
|
28
|
+
data_structured = MessagePack.pack(object_structured)
|
29
|
+
|
30
|
+
class Extended
|
31
|
+
def to_msgpack_ext
|
32
|
+
MessagePack.pack({})
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.from_msgpack_ext(data)
|
36
|
+
MessagePack.unpack(data)
|
37
|
+
Extended.new
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
object_extended = {
|
42
|
+
'extended' => Extended.new
|
43
|
+
}
|
44
|
+
|
45
|
+
extended_packer = MessagePack::Packer.new
|
46
|
+
extended_packer.register_type(0x00, Extended, :to_msgpack_ext)
|
47
|
+
data_extended = extended_packer.pack(object_extended).to_s
|
48
|
+
|
49
|
+
Benchmark.ips do |x|
|
50
|
+
x.report('pack-plain') do
|
51
|
+
MessagePack.pack(object_plain)
|
52
|
+
end
|
53
|
+
|
54
|
+
x.report('pack-structured') do
|
55
|
+
MessagePack.pack(object_structured)
|
56
|
+
end
|
57
|
+
|
58
|
+
x.report('pack-extended') do
|
59
|
+
packer = MessagePack::Packer.new
|
60
|
+
packer.register_type(0x00, Extended, :to_msgpack_ext)
|
61
|
+
packer.pack(object_extended).to_s
|
62
|
+
end
|
63
|
+
|
64
|
+
x.report('unpack-plain') do
|
65
|
+
MessagePack.unpack(data_plain)
|
66
|
+
end
|
67
|
+
|
68
|
+
x.report('unpack-structured') do
|
69
|
+
MessagePack.unpack(data_structured)
|
70
|
+
end
|
71
|
+
|
72
|
+
x.report('unpack-extended') do
|
73
|
+
unpacker = MessagePack::Unpacker.new
|
74
|
+
unpacker.register_type(0x00, Extended, :from_msgpack_ext)
|
75
|
+
unpacker.feed data_extended
|
76
|
+
unpacker.read
|
77
|
+
end
|
78
|
+
end
|
data/ext/msgpack/buffer.c
CHANGED
@@ -300,30 +300,6 @@ static inline void _msgpack_buffer_add_new_chunk(msgpack_buffer_t* b)
|
|
300
300
|
}
|
301
301
|
}
|
302
302
|
|
303
|
-
static inline void _msgpack_buffer_append_reference(msgpack_buffer_t* b, VALUE string)
|
304
|
-
{
|
305
|
-
VALUE mapped_string = rb_str_dup(string);
|
306
|
-
ENCODING_SET(mapped_string, msgpack_rb_encindex_ascii8bit);
|
307
|
-
|
308
|
-
_msgpack_buffer_add_new_chunk(b);
|
309
|
-
|
310
|
-
char* data = RSTRING_PTR(mapped_string);
|
311
|
-
size_t length = RSTRING_LEN(mapped_string);
|
312
|
-
|
313
|
-
b->tail.first = (char*) data;
|
314
|
-
b->tail.last = (char*) data + length;
|
315
|
-
b->tail.mapped_string = mapped_string;
|
316
|
-
b->tail.mem = NULL;
|
317
|
-
|
318
|
-
/* msgpack_buffer_writable_size should return 0 for mapped chunk */
|
319
|
-
b->tail_buffer_end = b->tail.last;
|
320
|
-
|
321
|
-
/* consider read_buffer */
|
322
|
-
if(b->head == &b->tail) {
|
323
|
-
b->read_buffer = b->tail.first;
|
324
|
-
}
|
325
|
-
}
|
326
|
-
|
327
303
|
void _msgpack_buffer_append_long_string(msgpack_buffer_t* b, VALUE string)
|
328
304
|
{
|
329
305
|
size_t length = RSTRING_LEN(string);
|
@@ -332,16 +308,9 @@ void _msgpack_buffer_append_long_string(msgpack_buffer_t* b, VALUE string)
|
|
332
308
|
msgpack_buffer_flush(b);
|
333
309
|
if (ENCODING_GET(string) == msgpack_rb_encindex_ascii8bit) {
|
334
310
|
rb_funcall(b->io, b->io_write_all_method, 1, string);
|
335
|
-
} else if(!STR_DUP_LIKELY_DOES_COPY(string)) {
|
336
|
-
VALUE s = rb_str_dup(string);
|
337
|
-
ENCODING_SET(s, msgpack_rb_encindex_ascii8bit);
|
338
|
-
rb_funcall(b->io, b->io_write_all_method, 1, s);
|
339
311
|
} else {
|
340
312
|
msgpack_buffer_append(b, RSTRING_PTR(string), length);
|
341
313
|
}
|
342
|
-
} else if(!STR_DUP_LIKELY_DOES_COPY(string)) {
|
343
|
-
_msgpack_buffer_append_reference(b, string);
|
344
|
-
|
345
314
|
} else {
|
346
315
|
msgpack_buffer_append(b, RSTRING_PTR(string), length);
|
347
316
|
}
|
@@ -619,13 +588,13 @@ size_t msgpack_buffer_flush_to_io(msgpack_buffer_t* b, VALUE io, ID write_method
|
|
619
588
|
size_t _msgpack_buffer_feed_from_io(msgpack_buffer_t* b)
|
620
589
|
{
|
621
590
|
if(b->io_buffer == Qnil) {
|
622
|
-
b->io_buffer = rb_funcall(b->io, b->io_partial_read_method, 1,
|
591
|
+
b->io_buffer = rb_funcall(b->io, b->io_partial_read_method, 1, SIZET2NUM(b->io_buffer_size));
|
623
592
|
if(b->io_buffer == Qnil) {
|
624
593
|
rb_raise(rb_eEOFError, "IO reached end of file");
|
625
594
|
}
|
626
595
|
StringValue(b->io_buffer);
|
627
596
|
} else {
|
628
|
-
VALUE ret = rb_funcall(b->io, b->io_partial_read_method, 2,
|
597
|
+
VALUE ret = rb_funcall(b->io, b->io_partial_read_method, 2, SIZET2NUM(b->io_buffer_size), b->io_buffer);
|
629
598
|
if(ret == Qnil) {
|
630
599
|
rb_raise(rb_eEOFError, "IO reached end of file");
|
631
600
|
}
|
@@ -646,7 +615,7 @@ size_t _msgpack_buffer_read_from_io_to_string(msgpack_buffer_t* b, VALUE string,
|
|
646
615
|
{
|
647
616
|
if(RSTRING_LEN(string) == 0) {
|
648
617
|
/* direct read */
|
649
|
-
VALUE ret = rb_funcall(b->io, b->io_partial_read_method, 2,
|
618
|
+
VALUE ret = rb_funcall(b->io, b->io_partial_read_method, 2, SIZET2NUM(length), string);
|
650
619
|
if(ret == Qnil) {
|
651
620
|
return 0;
|
652
621
|
}
|
@@ -658,7 +627,7 @@ size_t _msgpack_buffer_read_from_io_to_string(msgpack_buffer_t* b, VALUE string,
|
|
658
627
|
b->io_buffer = rb_str_buf_new(0);
|
659
628
|
}
|
660
629
|
|
661
|
-
VALUE ret = rb_funcall(b->io, b->io_partial_read_method, 2,
|
630
|
+
VALUE ret = rb_funcall(b->io, b->io_partial_read_method, 2, SIZET2NUM(length), b->io_buffer);
|
662
631
|
if(ret == Qnil) {
|
663
632
|
return 0;
|
664
633
|
}
|
@@ -674,7 +643,7 @@ size_t _msgpack_buffer_skip_from_io(msgpack_buffer_t* b, size_t length)
|
|
674
643
|
b->io_buffer = rb_str_buf_new(0);
|
675
644
|
}
|
676
645
|
|
677
|
-
VALUE ret = rb_funcall(b->io, b->io_partial_read_method, 2,
|
646
|
+
VALUE ret = rb_funcall(b->io, b->io_partial_read_method, 2, SIZET2NUM(length), b->io_buffer);
|
678
647
|
if(ret == Qnil) {
|
679
648
|
return 0;
|
680
649
|
}
|
data/ext/msgpack/buffer.h
CHANGED
@@ -49,6 +49,10 @@
|
|
49
49
|
|
50
50
|
#define NO_MAPPED_STRING ((VALUE)0)
|
51
51
|
|
52
|
+
#ifndef RB_ENC_INTERNED_STR_NULL_CHECK
|
53
|
+
#define RB_ENC_INTERNED_STR_NULL_CHECK 0
|
54
|
+
#endif
|
55
|
+
|
52
56
|
extern int msgpack_rb_encindex_utf8;
|
53
57
|
extern int msgpack_rb_encindex_usascii;
|
54
58
|
extern int msgpack_rb_encindex_ascii8bit;
|
@@ -456,7 +460,11 @@ static inline VALUE msgpack_buffer_read_top_as_string(msgpack_buffer_t* b, size_
|
|
456
460
|
|
457
461
|
#ifdef HAVE_RB_ENC_INTERNED_STR
|
458
462
|
if (will_be_frozen) {
|
459
|
-
|
463
|
+
if (RB_ENC_INTERNED_STR_NULL_CHECK && length == 0) {
|
464
|
+
result = rb_enc_interned_str("", length, utf8 ? rb_utf8_encoding() : rb_ascii8bit_encoding());
|
465
|
+
} else {
|
466
|
+
result = rb_enc_interned_str(b->read_buffer, length, utf8 ? rb_utf8_encoding() : rb_ascii8bit_encoding());
|
467
|
+
}
|
460
468
|
} else {
|
461
469
|
if (utf8) {
|
462
470
|
result = rb_utf8_str_new(b->read_buffer, length);
|
data/ext/msgpack/buffer_class.c
CHANGED
@@ -96,17 +96,17 @@ void MessagePack_Buffer_set_options(msgpack_buffer_t* b, VALUE io, VALUE options
|
|
96
96
|
|
97
97
|
v = rb_hash_aref(options, sym_read_reference_threshold);
|
98
98
|
if(v != Qnil) {
|
99
|
-
msgpack_buffer_set_read_reference_threshold(b,
|
99
|
+
msgpack_buffer_set_read_reference_threshold(b, NUM2SIZET(v));
|
100
100
|
}
|
101
101
|
|
102
102
|
v = rb_hash_aref(options, sym_write_reference_threshold);
|
103
103
|
if(v != Qnil) {
|
104
|
-
msgpack_buffer_set_write_reference_threshold(b,
|
104
|
+
msgpack_buffer_set_write_reference_threshold(b, NUM2SIZET(v));
|
105
105
|
}
|
106
106
|
|
107
107
|
v = rb_hash_aref(options, sym_io_buffer_size);
|
108
108
|
if(v != Qnil) {
|
109
|
-
msgpack_buffer_set_io_buffer_size(b,
|
109
|
+
msgpack_buffer_set_io_buffer_size(b, NUM2SIZET(v));
|
110
110
|
}
|
111
111
|
}
|
112
112
|
}
|
@@ -301,11 +301,11 @@ static VALUE Buffer_skip(VALUE self, VALUE sn)
|
|
301
301
|
|
302
302
|
/* do nothing */
|
303
303
|
if(n == 0) {
|
304
|
-
return
|
304
|
+
return INT2NUM(0);
|
305
305
|
}
|
306
306
|
|
307
307
|
size_t sz = read_until_eof(b, Qnil, n);
|
308
|
-
return
|
308
|
+
return SIZET2NUM(sz);
|
309
309
|
}
|
310
310
|
|
311
311
|
static VALUE Buffer_skip_all(VALUE self, VALUE sn)
|
@@ -473,7 +473,7 @@ static VALUE Buffer_write_to(VALUE self, VALUE io)
|
|
473
473
|
{
|
474
474
|
BUFFER(self, b);
|
475
475
|
size_t sz = msgpack_buffer_flush_to_io(b, io, s_write, true);
|
476
|
-
return
|
476
|
+
return SIZET2NUM(sz);
|
477
477
|
}
|
478
478
|
|
479
479
|
void MessagePack_Buffer_module_init(VALUE mMessagePack)
|
data/ext/msgpack/compat.h
CHANGED
@@ -22,104 +22,5 @@
|
|
22
22
|
#include "ruby.h"
|
23
23
|
#include "ruby/encoding.h"
|
24
24
|
|
25
|
-
#if defined(HAVE_RUBY_ST_H)
|
26
|
-
# include "ruby/st.h" /* ruby hash on Ruby 1.9 */
|
27
|
-
#elif defined(HAVE_ST_H)
|
28
|
-
# include "st.h" /* ruby hash on Ruby 1.8 */
|
29
|
-
#endif
|
30
|
-
|
31
|
-
|
32
|
-
/*
|
33
|
-
* ZALLOC_N (ruby 2.2 or later)
|
34
|
-
*/
|
35
|
-
#ifndef RB_ZALLOC_N
|
36
|
-
# define RB_ZALLOC_N(type,n) ((type*)ruby_xcalloc((size_t)(n),sizeof(type)))
|
37
|
-
#endif
|
38
|
-
#ifndef ZALLOC_N
|
39
|
-
# define ZALLOC_N(type,n) RB_ZALLOC_N(type,n)
|
40
|
-
#endif
|
41
|
-
|
42
|
-
|
43
|
-
/*
|
44
|
-
* define STR_DUP_LIKELY_DOES_COPY
|
45
|
-
* check rb_str_dup actually copies the string or not
|
46
|
-
*/
|
47
|
-
#if defined(RUBY_VM) && defined(FL_ALL) && defined(FL_USER1) && defined(FL_USER3) /* MRI 1.9 */
|
48
|
-
# define STR_DUP_LIKELY_DOES_COPY(str) FL_ALL(str, FL_USER1|FL_USER3) /* same as STR_ASSOC_P(str) */
|
49
|
-
|
50
|
-
#elif defined(FL_TEST) && defined(ELTS_SHARED) /* MRI 1.8 */
|
51
|
-
# define STR_DUP_LIKELY_DOES_COPY(str) (!FL_TEST(str, ELTS_SHARED))
|
52
|
-
|
53
|
-
//#elif defined(RUBINIUS) || defined(JRUBY) /* Rubinius and JRuby */
|
54
|
-
#else
|
55
|
-
# define STR_DUP_LIKELY_DOES_COPY(str) (1)
|
56
|
-
|
57
|
-
#endif
|
58
|
-
|
59
|
-
|
60
|
-
/*
|
61
|
-
* SIZET2NUM
|
62
|
-
*/
|
63
|
-
#ifndef SIZET2NUM /* MRI 1.8 */
|
64
|
-
# define SIZET2NUM(v) ULL2NUM(v)
|
65
|
-
#endif
|
66
|
-
|
67
|
-
|
68
|
-
/*
|
69
|
-
* rb_errinfo()
|
70
|
-
*/
|
71
|
-
#if defined(RUBY_VM) /* MRI 1.9 */
|
72
|
-
# define COMPAT_RERAISE rb_exc_raise(rb_errinfo())
|
73
|
-
|
74
|
-
#elif defined(JRUBY) /* JRuby */
|
75
|
-
# define COMPAT_RERAISE rb_exc_raise(rb_gv_get("$!"))
|
76
|
-
|
77
|
-
#else /* MRI 1.8 and Rubinius */
|
78
|
-
# define COMPAT_RERAISE rb_exc_raise(ruby_errinfo)
|
79
|
-
#endif
|
80
|
-
|
81
|
-
|
82
|
-
/*
|
83
|
-
* RBIGNUM_POSITIVE_P
|
84
|
-
*/
|
85
|
-
#ifndef RBIGNUM_POSITIVE_P
|
86
|
-
# if defined(RUBINIUS) /* Rubinius <= v1.2.3 */
|
87
|
-
# define RBIGNUM_POSITIVE_P(b) (rb_funcall(b, rb_intern(">="), 1, INT2FIX(0)) == Qtrue)
|
88
|
-
|
89
|
-
# elif defined(JRUBY) /* JRuby */
|
90
|
-
# define RBIGNUM_POSITIVE_P(b) (rb_funcall(b, rb_intern(">="), 1, INT2FIX(0)) == Qtrue)
|
91
|
-
# define rb_big2ull(b) rb_num2ull(b)
|
92
|
-
/*#define rb_big2ll(b) rb_num2ll(b)*/
|
93
|
-
|
94
|
-
# else /* MRI 1.8 */
|
95
|
-
# define RBIGNUM_POSITIVE_P(b) (RBIGNUM(b)->sign)
|
96
|
-
# endif
|
97
|
-
#endif
|
98
|
-
|
99
|
-
|
100
|
-
/*
|
101
|
-
* RSTRING_PTR, RSTRING_LEN
|
102
|
-
*/
|
103
|
-
#ifndef RSTRING_PTR /* MRI 1.8.5 */
|
104
|
-
# define RSTRING_PTR(s) (RSTRING(s)->ptr)
|
105
|
-
#endif
|
106
|
-
|
107
|
-
#ifndef RSTRING_LEN /* MRI 1.8.5 */
|
108
|
-
# define RSTRING_LEN(s) (RSTRING(s)->len)
|
109
|
-
#endif
|
110
|
-
|
111
|
-
|
112
|
-
/*
|
113
|
-
* RSTRUCT_GET
|
114
|
-
*/
|
115
|
-
#ifndef RSTRUCT_GET
|
116
|
-
# ifdef RSTRUCT_PTR /* MRI <= 2.0.0 */
|
117
|
-
# define RSTRUCT_GET(st, idx) (RSTRUCT_PTR(st)[idx])
|
118
|
-
# else /* Rubinius */
|
119
|
-
# define RSTRUCT_GET(st, idx) (rb_struct_aref(st, INT2FIX(idx)))
|
120
|
-
# endif
|
121
|
-
#endif
|
122
|
-
|
123
|
-
|
124
25
|
#endif
|
125
26
|
|
data/ext/msgpack/extconf.rb
CHANGED
@@ -2,24 +2,23 @@ require 'mkmf'
|
|
2
2
|
|
3
3
|
have_header("ruby/st.h")
|
4
4
|
have_header("st.h")
|
5
|
-
have_func("rb_enc_interned_str", "ruby.h")
|
5
|
+
have_func("rb_enc_interned_str", "ruby.h") # Ruby 3.0+
|
6
|
+
have_func("rb_hash_new_capa", "ruby.h") # Ruby 3.2+
|
6
7
|
|
7
8
|
unless RUBY_PLATFORM.include? 'mswin'
|
8
|
-
$CFLAGS << %[ -I.. -Wall -O3
|
9
|
+
$CFLAGS << %[ -I.. -Wall -O3 #{RbConfig::CONFIG["debugflags"]} -std=gnu99]
|
9
10
|
end
|
10
11
|
#$CFLAGS << %[ -DDISABLE_RMEM]
|
11
12
|
#$CFLAGS << %[ -DDISABLE_RMEM_REUSE_INTERNAL_FRAGMENT]
|
12
13
|
#$CFLAGS << %[ -DDISABLE_BUFFER_READ_REFERENCE_OPTIMIZE]
|
13
14
|
#$CFLAGS << %[ -DDISABLE_BUFFER_READ_TO_S_OPTIMIZE]
|
14
15
|
|
15
|
-
if
|
16
|
-
#
|
17
|
-
$CFLAGS <<
|
18
|
-
# Rubinius C extensions don't grab GVL while rmem is not thread safe
|
19
|
-
$CFLAGS << %[ -DDISABLE_RMEM]
|
16
|
+
if RUBY_VERSION.start_with?('3.0.')
|
17
|
+
# https://bugs.ruby-lang.org/issues/18772
|
18
|
+
$CFLAGS << ' -DRB_ENC_INTERNED_STR_NULL_CHECK=1 '
|
20
19
|
end
|
21
20
|
|
22
|
-
# checking if Hash#[]= (rb_hash_aset) dedupes string keys
|
21
|
+
# checking if Hash#[]= (rb_hash_aset) dedupes string keys (Ruby 2.6+)
|
23
22
|
h = {}
|
24
23
|
x = {}
|
25
24
|
r = rand.to_s
|
@@ -32,7 +31,7 @@ else
|
|
32
31
|
end
|
33
32
|
|
34
33
|
|
35
|
-
# checking if String#-@ (str_uminus) dedupes... '
|
34
|
+
# checking if String#-@ (str_uminus) dedupes... ' (Ruby 2.5+)
|
36
35
|
begin
|
37
36
|
a = -(%w(t e s t).join)
|
38
37
|
b = -(%w(t e s t).join)
|
@@ -45,7 +44,7 @@ rescue NoMethodError
|
|
45
44
|
$CFLAGS << ' -DSTR_UMINUS_DEDUPE=0 '
|
46
45
|
end
|
47
46
|
|
48
|
-
# checking if String#-@ (str_uminus) directly interns frozen strings... '
|
47
|
+
# checking if String#-@ (str_uminus) directly interns frozen strings... ' (Ruby 3.0+)
|
49
48
|
begin
|
50
49
|
s = rand.to_s.freeze
|
51
50
|
if (-s).equal?(s) && (-s.dup).equal?(s)
|
@@ -62,4 +61,3 @@ if warnflags = CONFIG['warnflags']
|
|
62
61
|
end
|
63
62
|
|
64
63
|
create_makefile('msgpack/msgpack')
|
65
|
-
|
data/ext/msgpack/packer.c
CHANGED
@@ -18,24 +18,10 @@
|
|
18
18
|
|
19
19
|
#include "packer.h"
|
20
20
|
|
21
|
-
#ifdef RUBINIUS
|
22
|
-
static ID s_to_iter;
|
23
|
-
static ID s_next;
|
24
|
-
static ID s_key;
|
25
|
-
static ID s_value;
|
26
|
-
#endif
|
27
|
-
|
28
21
|
static ID s_call;
|
29
22
|
|
30
23
|
void msgpack_packer_static_init()
|
31
24
|
{
|
32
|
-
#ifdef RUBINIUS
|
33
|
-
s_to_iter = rb_intern("to_iter");
|
34
|
-
s_next = rb_intern("next");
|
35
|
-
s_key = rb_intern("key");
|
36
|
-
s_value = rb_intern("value");
|
37
|
-
#endif
|
38
|
-
|
39
25
|
s_call = rb_intern("call");
|
40
26
|
}
|
41
27
|
|
@@ -108,17 +94,7 @@ void msgpack_packer_write_hash_value(msgpack_packer_t* pk, VALUE v)
|
|
108
94
|
unsigned int len32 = (unsigned int)len;
|
109
95
|
msgpack_packer_write_map_header(pk, len32);
|
110
96
|
|
111
|
-
#ifdef RUBINIUS
|
112
|
-
VALUE iter = rb_funcall(v, s_to_iter, 0);
|
113
|
-
VALUE entry = Qnil;
|
114
|
-
while(RTEST(entry = rb_funcall(iter, s_next, 1, entry))) {
|
115
|
-
VALUE key = rb_funcall(entry, s_key, 0);
|
116
|
-
VALUE val = rb_funcall(entry, s_value, 0);
|
117
|
-
write_hash_foreach(key, val, (VALUE) pk);
|
118
|
-
}
|
119
|
-
#else
|
120
97
|
rb_hash_foreach(v, write_hash_foreach, (VALUE) pk);
|
121
|
-
#endif
|
122
98
|
}
|
123
99
|
|
124
100
|
struct msgpack_call_proc_args_t;
|
data/ext/msgpack/packer.h
CHANGED
@@ -408,13 +408,7 @@ static inline bool msgpack_packer_is_utf8_compat_string(VALUE v, int encindex)
|
|
408
408
|
{
|
409
409
|
return encindex == msgpack_rb_encindex_utf8
|
410
410
|
|| encindex == msgpack_rb_encindex_usascii
|
411
|
-
|
412
|
-
/* Because ENC_CODERANGE_ASCIIONLY does not scan string, it may return ENC_CODERANGE_UNKNOWN unlike */
|
413
|
-
/* rb_enc_str_asciionly_p. It is always faster than rb_str_encode if it is available. */
|
414
|
-
/* Very old Rubinius (< v1.3.1) doesn't have ENC_CODERANGE_ASCIIONLY. */
|
415
|
-
|| (rb_enc_asciicompat(rb_enc_from_index(encindex)) && ENC_CODERANGE_ASCIIONLY(v))
|
416
|
-
#endif
|
417
|
-
;
|
411
|
+
|| (rb_enc_asciicompat(rb_enc_from_index(encindex)) && ENC_CODERANGE_ASCIIONLY(v));
|
418
412
|
}
|
419
413
|
|
420
414
|
static inline void msgpack_packer_write_string_value(msgpack_packer_t* pk, VALUE v)
|
data/ext/msgpack/packer_class.c
CHANGED
@@ -322,7 +322,7 @@ static VALUE Packer_write_to(VALUE self, VALUE io)
|
|
322
322
|
{
|
323
323
|
PACKER(self, pk);
|
324
324
|
size_t sz = msgpack_buffer_flush_to_io(PACKER_BUFFER_(pk), io, s_write, true);
|
325
|
-
return
|
325
|
+
return SIZET2NUM(sz);
|
326
326
|
}
|
327
327
|
|
328
328
|
//static VALUE Packer_append(VALUE self, VALUE string_or_buffer)
|
data/ext/msgpack/unpacker.c
CHANGED
@@ -34,6 +34,13 @@ static ID s_call;
|
|
34
34
|
static msgpack_rmem_t s_stack_rmem;
|
35
35
|
#endif
|
36
36
|
|
37
|
+
#if !defined(HAVE_RB_HASH_NEW_CAPA)
|
38
|
+
static inline VALUE rb_hash_new_capa(long capa)
|
39
|
+
{
|
40
|
+
return rb_hash_new();
|
41
|
+
}
|
42
|
+
#endif
|
43
|
+
|
37
44
|
void msgpack_unpacker_static_init()
|
38
45
|
{
|
39
46
|
#ifdef UNPACKER_STACK_RMEM
|
@@ -170,6 +177,9 @@ static inline int object_complete_symbol(msgpack_unpacker_t* uk, VALUE object)
|
|
170
177
|
static inline int object_complete_ext(msgpack_unpacker_t* uk, int ext_type, VALUE str)
|
171
178
|
{
|
172
179
|
if (uk->optimized_symbol_ext_type && ext_type == uk->symbol_ext_type) {
|
180
|
+
if (RB_UNLIKELY(NIL_P(str))) { // empty extension is returned as Qnil
|
181
|
+
return object_complete_symbol(uk, ID2SYM(rb_intern3("", 0, rb_utf8_encoding())));
|
182
|
+
}
|
173
183
|
return object_complete_symbol(uk, rb_str_intern(str));
|
174
184
|
}
|
175
185
|
|
@@ -371,9 +381,6 @@ static int read_primitive(msgpack_unpacker_t* uk)
|
|
371
381
|
|
372
382
|
SWITCH_RANGE(b, 0xa0, 0xbf) // FixRaw / fixstr
|
373
383
|
int count = b & 0x1f;
|
374
|
-
if(count == 0) {
|
375
|
-
return object_complete(uk, rb_utf8_str_new_static("", 0));
|
376
|
-
}
|
377
384
|
/* read_raw_body_begin sets uk->reading_raw */
|
378
385
|
uk->reading_raw_remaining = count;
|
379
386
|
return read_raw_body_begin(uk, RAW_TYPE_STRING);
|
@@ -390,7 +397,7 @@ static int read_primitive(msgpack_unpacker_t* uk)
|
|
390
397
|
if(count == 0) {
|
391
398
|
return object_complete(uk, rb_hash_new());
|
392
399
|
}
|
393
|
-
return _msgpack_unpacker_stack_push(uk, STACK_TYPE_MAP_KEY, count*2,
|
400
|
+
return _msgpack_unpacker_stack_push(uk, STACK_TYPE_MAP_KEY, count*2, rb_hash_new_capa(count));
|
394
401
|
|
395
402
|
SWITCH_RANGE(b, 0xc0, 0xdf) // Variable
|
396
403
|
switch(b) {
|
@@ -473,7 +480,7 @@ static int read_primitive(msgpack_unpacker_t* uk)
|
|
473
480
|
{
|
474
481
|
READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 4);
|
475
482
|
uint32_t u32 = _msgpack_be32(cb->u32);
|
476
|
-
return object_complete(uk, ULONG2NUM(
|
483
|
+
return object_complete(uk, ULONG2NUM(u32)); // long at least 32 bits
|
477
484
|
}
|
478
485
|
|
479
486
|
case 0xcf: // unsigned int 64
|
@@ -501,7 +508,7 @@ static int read_primitive(msgpack_unpacker_t* uk)
|
|
501
508
|
{
|
502
509
|
READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 4);
|
503
510
|
int32_t i32 = _msgpack_be32(cb->i32);
|
504
|
-
return object_complete(uk, LONG2NUM(
|
511
|
+
return object_complete(uk, LONG2NUM(i32)); // long at least 32 bits
|
505
512
|
}
|
506
513
|
|
507
514
|
case 0xd3: // signed int 64
|
@@ -556,9 +563,6 @@ static int read_primitive(msgpack_unpacker_t* uk)
|
|
556
563
|
{
|
557
564
|
READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 1);
|
558
565
|
uint8_t count = cb->u8;
|
559
|
-
if(count == 0) {
|
560
|
-
return object_complete(uk, rb_utf8_str_new_static("", 0));
|
561
|
-
}
|
562
566
|
/* read_raw_body_begin sets uk->reading_raw */
|
563
567
|
uk->reading_raw_remaining = count;
|
564
568
|
return read_raw_body_begin(uk, RAW_TYPE_STRING);
|
@@ -568,9 +572,6 @@ static int read_primitive(msgpack_unpacker_t* uk)
|
|
568
572
|
{
|
569
573
|
READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 2);
|
570
574
|
uint16_t count = _msgpack_be16(cb->u16);
|
571
|
-
if(count == 0) {
|
572
|
-
return object_complete(uk, rb_utf8_str_new_static("", 0));
|
573
|
-
}
|
574
575
|
/* read_raw_body_begin sets uk->reading_raw */
|
575
576
|
uk->reading_raw_remaining = count;
|
576
577
|
return read_raw_body_begin(uk, RAW_TYPE_STRING);
|
@@ -580,9 +581,6 @@ static int read_primitive(msgpack_unpacker_t* uk)
|
|
580
581
|
{
|
581
582
|
READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 4);
|
582
583
|
uint32_t count = _msgpack_be32(cb->u32);
|
583
|
-
if(count == 0) {
|
584
|
-
return object_complete(uk, rb_utf8_str_new_static("", 0));
|
585
|
-
}
|
586
584
|
/* read_raw_body_begin sets uk->reading_raw */
|
587
585
|
uk->reading_raw_remaining = count;
|
588
586
|
return read_raw_body_begin(uk, RAW_TYPE_STRING);
|
@@ -592,9 +590,6 @@ static int read_primitive(msgpack_unpacker_t* uk)
|
|
592
590
|
{
|
593
591
|
READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 1);
|
594
592
|
uint8_t count = cb->u8;
|
595
|
-
if(count == 0) {
|
596
|
-
return object_complete(uk, rb_str_new_static("", 0));
|
597
|
-
}
|
598
593
|
/* read_raw_body_begin sets uk->reading_raw */
|
599
594
|
uk->reading_raw_remaining = count;
|
600
595
|
return read_raw_body_begin(uk, RAW_TYPE_BINARY);
|
@@ -604,9 +599,6 @@ static int read_primitive(msgpack_unpacker_t* uk)
|
|
604
599
|
{
|
605
600
|
READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 2);
|
606
601
|
uint16_t count = _msgpack_be16(cb->u16);
|
607
|
-
if(count == 0) {
|
608
|
-
return object_complete(uk, rb_str_new_static("", 0));
|
609
|
-
}
|
610
602
|
/* read_raw_body_begin sets uk->reading_raw */
|
611
603
|
uk->reading_raw_remaining = count;
|
612
604
|
return read_raw_body_begin(uk, RAW_TYPE_BINARY);
|
@@ -616,9 +608,6 @@ static int read_primitive(msgpack_unpacker_t* uk)
|
|
616
608
|
{
|
617
609
|
READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 4);
|
618
610
|
uint32_t count = _msgpack_be32(cb->u32);
|
619
|
-
if(count == 0) {
|
620
|
-
return object_complete(uk, rb_str_new_static("", 0));
|
621
|
-
}
|
622
611
|
/* read_raw_body_begin sets uk->reading_raw */
|
623
612
|
uk->reading_raw_remaining = count;
|
624
613
|
return read_raw_body_begin(uk, RAW_TYPE_BINARY);
|
@@ -651,7 +640,7 @@ static int read_primitive(msgpack_unpacker_t* uk)
|
|
651
640
|
if(count == 0) {
|
652
641
|
return object_complete(uk, rb_hash_new());
|
653
642
|
}
|
654
|
-
return _msgpack_unpacker_stack_push(uk, STACK_TYPE_MAP_KEY, count*2,
|
643
|
+
return _msgpack_unpacker_stack_push(uk, STACK_TYPE_MAP_KEY, count*2, rb_hash_new_capa(count));
|
655
644
|
}
|
656
645
|
|
657
646
|
case 0xdf: // map 32
|
@@ -661,7 +650,7 @@ static int read_primitive(msgpack_unpacker_t* uk)
|
|
661
650
|
if(count == 0) {
|
662
651
|
return object_complete(uk, rb_hash_new());
|
663
652
|
}
|
664
|
-
return _msgpack_unpacker_stack_push(uk, STACK_TYPE_MAP_KEY, count*2,
|
653
|
+
return _msgpack_unpacker_stack_push(uk, STACK_TYPE_MAP_KEY, count*2, rb_hash_new_capa(count));
|
665
654
|
}
|
666
655
|
|
667
656
|
default:
|
@@ -209,7 +209,7 @@ static VALUE Unpacker_read_array_header(VALUE self)
|
|
209
209
|
raise_unpacker_error(r);
|
210
210
|
}
|
211
211
|
|
212
|
-
return ULONG2NUM(size);
|
212
|
+
return ULONG2NUM(size); // long at least 32 bits
|
213
213
|
}
|
214
214
|
|
215
215
|
static VALUE Unpacker_read_map_header(VALUE self)
|
@@ -222,7 +222,7 @@ static VALUE Unpacker_read_map_header(VALUE self)
|
|
222
222
|
raise_unpacker_error((int)r);
|
223
223
|
}
|
224
224
|
|
225
|
-
return ULONG2NUM(size);
|
225
|
+
return ULONG2NUM(size); // long at least 32 bits
|
226
226
|
}
|
227
227
|
|
228
228
|
|
@@ -450,4 +450,3 @@ void MessagePack_Unpacker_module_init(VALUE mMessagePack)
|
|
450
450
|
|
451
451
|
rb_define_method(cMessagePack_Unpacker, "full_unpack", Unpacker_full_unpack, 0);
|
452
452
|
}
|
453
|
-
|
data/lib/msgpack/version.rb
CHANGED
data/msgpack.gemspec
CHANGED
data/spec/factory_spec.rb
CHANGED
@@ -474,6 +474,10 @@ describe MessagePack::Factory do
|
|
474
474
|
expect(roundtrip(:symbol)).to be :symbol
|
475
475
|
end
|
476
476
|
|
477
|
+
it 'works with empty symbol' do
|
478
|
+
expect(roundtrip(:"")).to be :""
|
479
|
+
end
|
480
|
+
|
477
481
|
it 'preserves encoding for ASCII symbols' do
|
478
482
|
expect(:symbol.encoding).to be Encoding::US_ASCII
|
479
483
|
expect(roundtrip(:symbol)).to be :symbol
|
data/spec/spec_helper.rb
CHANGED
@@ -20,7 +20,11 @@ require "msgpack/bigint"
|
|
20
20
|
if GC.respond_to?(:verify_compaction_references)
|
21
21
|
# This method was added in Ruby 3.0.0. Calling it this way asks the GC to
|
22
22
|
# move objects around, helping to find object movement bugs.
|
23
|
-
|
23
|
+
begin
|
24
|
+
GC.verify_compaction_references(double_heap: true, toward: :empty)
|
25
|
+
rescue NotImplementedError
|
26
|
+
# Some platforms don't support compaction
|
27
|
+
end
|
24
28
|
end
|
25
29
|
|
26
30
|
if GC.respond_to?(:auto_compact=)
|
data/spec/unpacker_spec.rb
CHANGED
@@ -707,6 +707,18 @@ describe MessagePack::Unpacker do
|
|
707
707
|
described_class.new(:freeze => true)
|
708
708
|
end
|
709
709
|
|
710
|
+
if (-"test").equal?(-"test") # RUBY_VERSION >= "2.5"
|
711
|
+
it 'dedups strings' do
|
712
|
+
interned_str = -"test"
|
713
|
+
roundtrip = MessagePack.unpack(MessagePack.pack(interned_str), freeze: true)
|
714
|
+
expect(roundtrip).to be interned_str
|
715
|
+
|
716
|
+
interned_str = -""
|
717
|
+
roundtrip = MessagePack.unpack(MessagePack.pack(interned_str), freeze: true)
|
718
|
+
expect(roundtrip).to be interned_str
|
719
|
+
end
|
720
|
+
end
|
721
|
+
|
710
722
|
it 'can freeze objects when using .unpack' do
|
711
723
|
parsed_struct = MessagePack.unpack(buffer, freeze: true)
|
712
724
|
parsed_struct.should == struct
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: msgpack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sadayuki Furuhashi
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2022-
|
13
|
+
date: 2022-07-25 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
@@ -96,6 +96,20 @@ dependencies:
|
|
96
96
|
- - ">="
|
97
97
|
- !ruby/object:Gem::Version
|
98
98
|
version: '0'
|
99
|
+
- !ruby/object:Gem::Dependency
|
100
|
+
name: benchmark-ips
|
101
|
+
requirement: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - "~>"
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: 2.10.0
|
106
|
+
type: :development
|
107
|
+
prerelease: false
|
108
|
+
version_requirements: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - "~>"
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: 2.10.0
|
99
113
|
description: MessagePack is a binary-based efficient object serialization library.
|
100
114
|
It enables to exchange structured objects between many languages like JSON. But
|
101
115
|
unlike JSON, it is very fast and small.
|
@@ -117,16 +131,7 @@ files:
|
|
117
131
|
- README.md
|
118
132
|
- Rakefile
|
119
133
|
- appveyor.yml
|
120
|
-
- bench/
|
121
|
-
- bench/pack_log.rb
|
122
|
-
- bench/pack_log_long.rb
|
123
|
-
- bench/pack_symbols.rb
|
124
|
-
- bench/run.sh
|
125
|
-
- bench/run_long.sh
|
126
|
-
- bench/run_symbols.sh
|
127
|
-
- bench/unpack.rb
|
128
|
-
- bench/unpack_log.rb
|
129
|
-
- bench/unpack_log_long.rb
|
134
|
+
- bench/bench.rb
|
130
135
|
- doclib/msgpack.rb
|
131
136
|
- doclib/msgpack/buffer.rb
|
132
137
|
- doclib/msgpack/core_ext.rb
|
@@ -231,7 +236,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
231
236
|
- !ruby/object:Gem::Version
|
232
237
|
version: '0'
|
233
238
|
requirements: []
|
234
|
-
rubygems_version: 3.
|
239
|
+
rubygems_version: 3.1.2
|
235
240
|
signing_key:
|
236
241
|
specification_version: 4
|
237
242
|
summary: MessagePack, a binary-based efficient data interchange format.
|
data/bench/pack.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'viiite'
|
2
|
-
require 'msgpack'
|
3
|
-
|
4
|
-
data = { 'hello' => 'world', 'nested' => ['structure', {value: 42}] }
|
5
|
-
data_sym = { hello: 'world', nested: ['structure', {value: 42}] }
|
6
|
-
|
7
|
-
data = MessagePack.pack(:hello => 'world', :nested => ['structure', {:value => 42}])
|
8
|
-
|
9
|
-
Viiite.bench do |b|
|
10
|
-
b.range_over([10_000, 100_000, 1000_000], :runs) do |runs|
|
11
|
-
b.report(:strings) do
|
12
|
-
runs.times do
|
13
|
-
MessagePack.pack(data)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
b.report(:symbols) do
|
18
|
-
runs.times do
|
19
|
-
MessagePack.pack(data_sym)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
data/bench/pack_log.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'viiite'
|
2
|
-
require 'msgpack'
|
3
|
-
|
4
|
-
data_plain = { 'message' => '127.0.0.1 - - [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326 "http://www.example.com/start.html" "Mozilla/4.08 [en] (Win98; I ;Nav)"' }
|
5
|
-
data_structure = {
|
6
|
-
'remote_host' => '127.0.0.1',
|
7
|
-
'remote_user' => '-',
|
8
|
-
'date' => '10/Oct/2000:13:55:36 -0700',
|
9
|
-
'request' => 'GET /apache_pb.gif HTTP/1.0',
|
10
|
-
'method' => 'GET',
|
11
|
-
'path' => '/apache_pb.gif',
|
12
|
-
'protocol' => 'HTTP/1.0',
|
13
|
-
'status' => 200,
|
14
|
-
'bytes' => 2326,
|
15
|
-
'referer' => 'http://www.example.com/start.html',
|
16
|
-
'agent' => 'Mozilla/4.08 [en] (Win98; I ;Nav)',
|
17
|
-
}
|
18
|
-
|
19
|
-
Viiite.bench do |b|
|
20
|
-
b.range_over([10_000, 100_000, 1000_000], :runs) do |runs|
|
21
|
-
b.report(:plain) do
|
22
|
-
runs.times do
|
23
|
-
MessagePack.pack(data_plain)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
b.report(:structure) do
|
28
|
-
runs.times do
|
29
|
-
MessagePack.pack(data_structure)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
data/bench/pack_log_long.rb
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
# viiite report --regroup bench,threads bench/pack_log_long.rb
|
2
|
-
|
3
|
-
require 'viiite'
|
4
|
-
require 'msgpack'
|
5
|
-
|
6
|
-
data_plain = { 'message' => '127.0.0.1 - - [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326 "http://www.example.com/start.html" "Mozilla/4.08 [en] (Win98; I ;Nav)"' }
|
7
|
-
data_structure = {
|
8
|
-
'remote_host' => '127.0.0.1',
|
9
|
-
'remote_user' => '-',
|
10
|
-
'date' => '10/Oct/2000:13:55:36 -0700',
|
11
|
-
'request' => 'GET /apache_pb.gif HTTP/1.0',
|
12
|
-
'method' => 'GET',
|
13
|
-
'path' => '/apache_pb.gif',
|
14
|
-
'protocol' => 'HTTP/1.0',
|
15
|
-
'status' => 200,
|
16
|
-
'bytes' => 2326,
|
17
|
-
'referer' => 'http://www.example.com/start.html',
|
18
|
-
'agent' => 'Mozilla/4.08 [en] (Win98; I ;Nav)',
|
19
|
-
}
|
20
|
-
|
21
|
-
seconds = 3600 # 1 hour
|
22
|
-
|
23
|
-
Viiite.bench do |b|
|
24
|
-
b.range_over([1, 2, 4, 8, 16], :threads) do |threads|
|
25
|
-
b.report(:plain) do
|
26
|
-
ths = []
|
27
|
-
end_at = Time.now + seconds
|
28
|
-
threads.times do
|
29
|
-
t = Thread.new do
|
30
|
-
packs = 0
|
31
|
-
while Time.now < end_at
|
32
|
-
10000.times do
|
33
|
-
MessagePack.pack(data_plain)
|
34
|
-
end
|
35
|
-
packs += 10000
|
36
|
-
end
|
37
|
-
packs
|
38
|
-
end
|
39
|
-
ths.push t
|
40
|
-
end
|
41
|
-
sum = ths.reduce(0){|r,t| r + t.value }
|
42
|
-
puts "MessagePack.pack, plain, #{threads} threads: #{sum} times, #{sum / seconds} times/second."
|
43
|
-
end
|
44
|
-
|
45
|
-
b.report(:structure) do
|
46
|
-
ths = []
|
47
|
-
end_at = Time.now + seconds
|
48
|
-
threads.times do
|
49
|
-
t = Thread.new do
|
50
|
-
packs = 0
|
51
|
-
while Time.now < end_at
|
52
|
-
10000.times do
|
53
|
-
MessagePack.pack(data_structure)
|
54
|
-
end
|
55
|
-
packs += 10000
|
56
|
-
end
|
57
|
-
packs
|
58
|
-
end
|
59
|
-
ths.push t
|
60
|
-
end
|
61
|
-
sum = ths.reduce(0){|r,t| r + t.value }
|
62
|
-
puts "MessagePack.pack, structured, #{threads} threads: #{sum} times, #{sum / seconds} times/second."
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
data/bench/pack_symbols.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'viiite'
|
2
|
-
require 'msgpack'
|
3
|
-
|
4
|
-
data = :symbol
|
5
|
-
|
6
|
-
Viiite.bench do |b|
|
7
|
-
b.variation_point :branch, `git rev-parse --abbrev-ref HEAD`
|
8
|
-
|
9
|
-
b.range_over([:symbol, :none], :reg_type) do |reg_type|
|
10
|
-
packer = MessagePack::Packer.new
|
11
|
-
packer.register_type(0x00, Symbol, :to_msgpack_ext) if reg_type == :symbol
|
12
|
-
|
13
|
-
b.range_over([100_000, 1_000_000, 10_000_000], :count) do |count|
|
14
|
-
packer.clear
|
15
|
-
b.report(:multi_run) do
|
16
|
-
count.times do
|
17
|
-
packer.pack(data)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
packer.clear
|
22
|
-
items_data = [].fill(data, 0, count)
|
23
|
-
b.report(:large_run) do
|
24
|
-
packer.pack(items_data)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
data/bench/run.sh
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/bin/sh
|
2
|
-
|
3
|
-
# prerequisites
|
4
|
-
# $ rbenv shell 2.2.1 (or jruby-x.x.x or ...)
|
5
|
-
# $ rake install
|
6
|
-
|
7
|
-
echo "pack"
|
8
|
-
viiite report --regroup bench,runs bench/pack.rb
|
9
|
-
echo "unpack"
|
10
|
-
viiite report --regroup bench,runs bench/unpack.rb
|
11
|
-
echo "pack log"
|
12
|
-
viiite report --regroup bench,runs bench/pack_log.rb
|
13
|
-
echo "unpack log"
|
14
|
-
viiite report --regroup bench,runs bench/unpack_log.rb
|
data/bench/run_long.sh
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
#!/bin/sh
|
2
|
-
|
3
|
-
# prerequisites
|
4
|
-
# $ sudo apt-get install sysstat
|
5
|
-
# $ rbenv shell 2.2.1 (or jruby-x.x.x or ...)
|
6
|
-
# $ rake install
|
7
|
-
|
8
|
-
# 60 * 600 : 60*60 * 5[threads] * 2[bench]
|
9
|
-
|
10
|
-
ruby -v
|
11
|
-
|
12
|
-
echo "pack log long"
|
13
|
-
viiite report --regroup bench,threads bench/pack_log_long.rb &
|
14
|
-
sar -o pack_log_long.sar -r 60 600 > /dev/null 2>&1 &
|
15
|
-
|
16
|
-
declare -i i=0
|
17
|
-
while [ $i -lt 600 ]; do
|
18
|
-
ps auxww | grep ruby | grep -v grep | awk '{print $5,$6;}' >> pack_log_long.mem.txt
|
19
|
-
i=i+1
|
20
|
-
sleep 60
|
21
|
-
done
|
22
|
-
|
23
|
-
sleep 120 # cool down
|
24
|
-
|
25
|
-
echo "unpack log long"
|
26
|
-
viiite report --regroup bench,threads bench/unpack_log_long.rb &
|
27
|
-
sar -o unpack_log_long.sar -r 60 600 > /dev/null 2>&1 &
|
28
|
-
|
29
|
-
i=0
|
30
|
-
while [ $i -lt 600 ]; do
|
31
|
-
ps auxww | grep ruby | grep -v grep | awk '{print $5,$6;}' >> pack_log_long.mem.txt
|
32
|
-
i=i+1
|
33
|
-
sleep 60
|
34
|
-
done
|
35
|
-
|
data/bench/run_symbols.sh
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
#!/bin/sh
|
2
|
-
|
3
|
-
# so master and this branch have the benchmark file in any case
|
4
|
-
cp bench/pack_symbols.rb bench/pack_symbols_tmp.rb
|
5
|
-
|
6
|
-
benchmark=""
|
7
|
-
current_branch=`git rev-parse --abbrev-ref HEAD`
|
8
|
-
|
9
|
-
for branch in master $current_branch; do
|
10
|
-
echo "Testing branch $branch"
|
11
|
-
git checkout $branch
|
12
|
-
|
13
|
-
echo "Installing gem..."
|
14
|
-
rake install
|
15
|
-
|
16
|
-
echo "Running benchmark..."
|
17
|
-
if [ "$benchmark" ]; then
|
18
|
-
benchmark+=$'\n'
|
19
|
-
fi
|
20
|
-
benchmark+=$(viiite run bench/pack_symbols_tmp.rb)
|
21
|
-
echo
|
22
|
-
done
|
23
|
-
|
24
|
-
rm bench/pack_symbols_tmp.rb
|
25
|
-
|
26
|
-
echo "$benchmark" | viiite report --regroup bench,reg_type,count,branch
|
data/bench/unpack.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'viiite'
|
2
|
-
require 'msgpack'
|
3
|
-
|
4
|
-
data = MessagePack.pack(:hello => 'world', :nested => ['structure', {:value => 42}])
|
5
|
-
|
6
|
-
Viiite.bench do |b|
|
7
|
-
b.range_over([10_000, 100_000, 1000_000], :runs) do |runs|
|
8
|
-
b.report(:strings) do
|
9
|
-
runs.times do
|
10
|
-
MessagePack.unpack(data)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
b.report(:symbols) do
|
15
|
-
options = {:symbolize_keys => true}
|
16
|
-
runs.times do
|
17
|
-
MessagePack.unpack(data, options)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
data/bench/unpack_log.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'viiite'
|
2
|
-
require 'msgpack'
|
3
|
-
|
4
|
-
data_plain = MessagePack.pack({ 'message' => '127.0.0.1 - - [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326 "http://www.example.com/start.html" "Mozilla/4.08 [en] (Win98; I ;Nav)"' })
|
5
|
-
|
6
|
-
data_structure = MessagePack.pack({
|
7
|
-
'remote_host' => '127.0.0.1',
|
8
|
-
'remote_user' => '-',
|
9
|
-
'date' => '10/Oct/2000:13:55:36 -0700',
|
10
|
-
'request' => 'GET /apache_pb.gif HTTP/1.0',
|
11
|
-
'method' => 'GET',
|
12
|
-
'path' => '/apache_pb.gif',
|
13
|
-
'protocol' => 'HTTP/1.0',
|
14
|
-
'status' => 200,
|
15
|
-
'bytes' => 2326,
|
16
|
-
'referer' => 'http://www.example.com/start.html',
|
17
|
-
'agent' => 'Mozilla/4.08 [en] (Win98; I ;Nav)',
|
18
|
-
})
|
19
|
-
|
20
|
-
Viiite.bench do |b|
|
21
|
-
b.range_over([10_000, 100_000, 1000_000], :runs) do |runs|
|
22
|
-
b.report(:plain) do
|
23
|
-
runs.times do
|
24
|
-
MessagePack.unpack(data_plain)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
b.report(:structure) do
|
29
|
-
runs.times do
|
30
|
-
MessagePack.unpack(data_structure)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
data/bench/unpack_log_long.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
# viiite report --regroup bench,threads bench/pack_log_long.rb
|
2
|
-
|
3
|
-
require 'viiite'
|
4
|
-
require 'msgpack'
|
5
|
-
|
6
|
-
data_plain = MessagePack.pack({
|
7
|
-
'message' => '127.0.0.1 - - [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326 "http://www.example.com/start.html" "Mozilla/4.08 [en] (Win98; I ;Nav)"'
|
8
|
-
})
|
9
|
-
data_structure = MessagePack.pack({
|
10
|
-
'remote_host' => '127.0.0.1',
|
11
|
-
'remote_user' => '-',
|
12
|
-
'date' => '10/Oct/2000:13:55:36 -0700',
|
13
|
-
'request' => 'GET /apache_pb.gif HTTP/1.0',
|
14
|
-
'method' => 'GET',
|
15
|
-
'path' => '/apache_pb.gif',
|
16
|
-
'protocol' => 'HTTP/1.0',
|
17
|
-
'status' => 200,
|
18
|
-
'bytes' => 2326,
|
19
|
-
'referer' => 'http://www.example.com/start.html',
|
20
|
-
'agent' => 'Mozilla/4.08 [en] (Win98; I ;Nav)',
|
21
|
-
})
|
22
|
-
|
23
|
-
seconds = 3600 # 1 hour
|
24
|
-
|
25
|
-
Viiite.bench do |b|
|
26
|
-
b.range_over([1, 2, 4, 8, 16], :threads) do |threads|
|
27
|
-
b.report(:plain) do
|
28
|
-
ths = []
|
29
|
-
end_at = Time.now + seconds
|
30
|
-
threads.times do
|
31
|
-
t = Thread.new do
|
32
|
-
packs = 0
|
33
|
-
while Time.now < end_at
|
34
|
-
10000.times do
|
35
|
-
MessagePack.unpack(data_plain)
|
36
|
-
end
|
37
|
-
packs += 10000
|
38
|
-
end
|
39
|
-
packs
|
40
|
-
end
|
41
|
-
ths.push t
|
42
|
-
end
|
43
|
-
sum = ths.reduce(0){|r,t| r + t.value }
|
44
|
-
puts "MessagePack.unpack, plain, #{threads} threads: #{sum} times, #{sum / seconds} times/second."
|
45
|
-
end
|
46
|
-
|
47
|
-
b.report(:structure) do
|
48
|
-
ths = []
|
49
|
-
end_at = Time.now + seconds
|
50
|
-
threads.times do
|
51
|
-
t = Thread.new do
|
52
|
-
packs = 0
|
53
|
-
while Time.now < end_at
|
54
|
-
10000.times do
|
55
|
-
MessagePack.unpack(data_structure)
|
56
|
-
end
|
57
|
-
packs += 10000
|
58
|
-
end
|
59
|
-
packs
|
60
|
-
end
|
61
|
-
ths.push t
|
62
|
-
end
|
63
|
-
sum = ths.reduce(0){|r,t| r + t.value }
|
64
|
-
puts "MessagePack.unpack, structured, #{threads} threads: #{sum} times, #{sum / seconds} times/second."
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|