Commit ee4fa4c
[ruby/json] json_string_unescape: Use the returned RString as buffer
Rather than to copy into a buffer to unescape and then copy that
buffer into the final string, we can directly copy into the final
string.
The downside is that if the string contains a lot of escaping, we
end up returning a string that's larger than strictly necessary, but
it's probably fine.
Before:
```
== Parsing twitter.json (567916 bytes)
ruby 3.3.4 (2024-07-09 revision ruby/json@be1089c8ec) +YJIT [arm64-darwin23]
Warming up --------------------------------------
json 56.000 i/100ms
oj 58.000 i/100ms
oj strict 74.000 i/100ms
Oj::Parser 76.000 i/100ms
rapidjson 52.000 i/100ms
Calculating -------------------------------------
json 556.659 (± 2.9%) i/s (1.80 ms/i) - 2.800k in 5.034719s
oj 604.077 (± 3.8%) i/s (1.66 ms/i) - 3.016k in 5.001546s
oj strict 706.942 (± 3.5%) i/s (1.41 ms/i) - 3.552k in 5.030954s
Oj::Parser 752.917 (± 3.2%) i/s (1.33 ms/i) - 3.800k in 5.052707s
rapidjson 546.470 (± 3.5%) i/s (1.83 ms/i) - 2.756k in 5.049855s
Comparison:
json: 556.7 i/s
Oj::Parser: 752.9 i/s - 1.35x faster
oj strict: 706.9 i/s - 1.27x faster
oj: 604.1 i/s - 1.09x faster
rapidjson: 546.5 i/s - same-ish: difference falls within error
== Parsing citm_catalog.json (1727030 bytes)
ruby 3.3.4 (2024-07-09 revision ruby/json@be1089c8ec) +YJIT [arm64-darwin23]
Warming up --------------------------------------
json 29.000 i/100ms
oj 32.000 i/100ms
oj strict 38.000 i/100ms
Oj::Parser 42.000 i/100ms
rapidjson 38.000 i/100ms
Calculating -------------------------------------
json 317.858 (± 3.1%) i/s (3.15 ms/i) - 1.595k in 5.023245s
oj 348.168 (± 2.6%) i/s (2.87 ms/i) - 1.760k in 5.058431s
oj strict 394.599 (± 2.8%) i/s (2.53 ms/i) - 1.976k in 5.012073s
Oj::Parser 403.771 (± 3.0%) i/s (2.48 ms/i) - 2.058k in 5.101578s
rapidjson 383.441 (± 3.7%) i/s (2.61 ms/i) - 1.938k in 5.061355s
Comparison:
json: 317.9 i/s
Oj::Parser: 403.8 i/s - 1.27x faster
oj strict: 394.6 i/s - 1.24x faster
rapidjson: 383.4 i/s - 1.21x faster
oj: 348.2 i/s - 1.10x faster
```
After:
```
== Parsing twitter.json (567916 bytes)
ruby 3.3.4 (2024-07-09 revision ruby/json@be1089c8ec) +YJIT [arm64-darwin23]
Warming up --------------------------------------
json 56.000 i/100ms
oj 62.000 i/100ms
oj strict 73.000 i/100ms
Oj::Parser 76.000 i/100ms
rapidjson 54.000 i/100ms
Calculating -------------------------------------
json 561.009 (± 7.5%) i/s (1.78 ms/i) - 2.800k in 5.039548s
oj 601.124 (± 4.3%) i/s (1.66 ms/i) - 3.038k in 5.064686s
oj strict 707.455 (± 3.4%) i/s (1.41 ms/i) - 3.577k in 5.062540s
Oj::Parser 751.799 (± 3.1%) i/s (1.33 ms/i) - 3.800k in 5.059509s
rapidjson 535.641 (± 3.2%) i/s (1.87 ms/i) - 2.700k in 5.045816s
Comparison:
json: 561.0 i/s
Oj::Parser: 751.8 i/s - 1.34x faster
oj strict: 707.5 i/s - 1.26x faster
oj: 601.1 i/s - same-ish: difference falls within error
rapidjson: 535.6 i/s - same-ish: difference falls within error
== Parsing citm_catalog.json (1727030 bytes)
ruby 3.3.4 (2024-07-09 revision ruby/json@be1089c8ec) +YJIT [arm64-darwin23]
Warming up --------------------------------------
json 30.000 i/100ms
oj 32.000 i/100ms
oj strict 36.000 i/100ms
Oj::Parser 42.000 i/100ms
rapidjson 39.000 i/100ms
Calculating -------------------------------------
json 313.248 (± 7.3%) i/s (3.19 ms/i) - 1.560k in 5.014118s
oj 341.977 (± 4.1%) i/s (2.92 ms/i) - 1.728k in 5.063332s
oj strict 387.062 (± 6.2%) i/s (2.58 ms/i) - 1.944k in 5.045961s
Oj::Parser 400.423 (± 4.0%) i/s (2.50 ms/i) - 2.016k in 5.044513s
rapidjson 379.046 (± 6.1%) i/s (2.64 ms/i) - 1.911k in 5.064461s
Comparison:
json: 313.2 i/s
Oj::Parser: 400.4 i/s - 1.28x faster
oj strict: 387.1 i/s - 1.24x faster
rapidjson: 379.0 i/s - 1.21x faster
oj: 342.0 i/s - same-ish: difference falls within error
```
ruby/json@5e1ec4a2681 parent b85a7a4 commit ee4fa4c
2 files changed
+33
-67
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1476 | 1476 | | |
1477 | 1477 | | |
1478 | 1478 | | |
1479 | | - | |
1480 | 1479 | | |
1481 | 1480 | | |
1482 | | - | |
1483 | 1481 | | |
1484 | 1482 | | |
1485 | 1483 | | |
| |||
1490 | 1488 | | |
1491 | 1489 | | |
1492 | 1490 | | |
1493 | | - | |
1494 | | - | |
1495 | | - | |
1496 | | - | |
1497 | | - | |
1498 | | - | |
1499 | | - | |
1500 | | - | |
1501 | | - | |
1502 | | - | |
1503 | | - | |
1504 | | - | |
1505 | | - | |
| 1491 | + | |
| 1492 | + | |
| 1493 | + | |
1506 | 1494 | | |
1507 | 1495 | | |
1508 | 1496 | | |
| |||
1536 | 1524 | | |
1537 | 1525 | | |
1538 | 1526 | | |
1539 | | - | |
1540 | | - | |
1541 | | - | |
1542 | 1527 | | |
1543 | 1528 | | |
1544 | 1529 | | |
| |||
1556 | 1541 | | |
1557 | 1542 | | |
1558 | 1543 | | |
1559 | | - | |
1560 | | - | |
1561 | | - | |
1562 | 1544 | | |
1563 | 1545 | | |
1564 | 1546 | | |
| |||
1591 | 1573 | | |
1592 | 1574 | | |
1593 | 1575 | | |
| 1576 | + | |
1594 | 1577 | | |
1595 | | - | |
1596 | | - | |
1597 | | - | |
1598 | | - | |
| 1578 | + | |
| 1579 | + | |
| 1580 | + | |
| 1581 | + | |
1599 | 1582 | | |
1600 | 1583 | | |
1601 | 1584 | | |
1602 | 1585 | | |
1603 | 1586 | | |
1604 | 1587 | | |
1605 | | - | |
| 1588 | + | |
1606 | 1589 | | |
1607 | 1590 | | |
1608 | 1591 | | |
1609 | 1592 | | |
1610 | 1593 | | |
1611 | 1594 | | |
1612 | 1595 | | |
1613 | | - | |
| 1596 | + | |
1614 | 1597 | | |
1615 | 1598 | | |
1616 | 1599 | | |
| |||
1631 | 1614 | | |
1632 | 1615 | | |
1633 | 1616 | | |
1634 | | - | |
| 1617 | + | |
1635 | 1618 | | |
1636 | 1619 | | |
1637 | 1620 | | |
1638 | 1621 | | |
1639 | | - | |
| 1622 | + | |
1640 | 1623 | | |
1641 | 1624 | | |
1642 | | - | |
| 1625 | + | |
1643 | 1626 | | |
1644 | 1627 | | |
1645 | 1628 | | |
| |||
1664 | 1647 | | |
1665 | 1648 | | |
1666 | 1649 | | |
1667 | | - | |
| 1650 | + | |
1668 | 1651 | | |
1669 | 1652 | | |
1670 | 1653 | | |
| |||
1674 | 1657 | | |
1675 | 1658 | | |
1676 | 1659 | | |
1677 | | - | |
| 1660 | + | |
1678 | 1661 | | |
1679 | 1662 | | |
1680 | 1663 | | |
1681 | 1664 | | |
1682 | 1665 | | |
1683 | 1666 | | |
1684 | | - | |
| 1667 | + | |
1685 | 1668 | | |
1686 | 1669 | | |
1687 | 1670 | | |
| |||
1757 | 1740 | | |
1758 | 1741 | | |
1759 | 1742 | | |
1760 | | - | |
| 1743 | + | |
1761 | 1744 | | |
1762 | 1745 | | |
1763 | 1746 | | |
| |||
1954 | 1937 | | |
1955 | 1938 | | |
1956 | 1939 | | |
1957 | | - | |
| 1940 | + | |
1958 | 1941 | | |
1959 | 1942 | | |
1960 | 1943 | | |
1961 | 1944 | | |
1962 | 1945 | | |
1963 | 1946 | | |
1964 | 1947 | | |
1965 | | - | |
| 1948 | + | |
1966 | 1949 | | |
1967 | 1950 | | |
1968 | 1951 | | |
| |||
1980 | 1963 | | |
1981 | 1964 | | |
1982 | 1965 | | |
1983 | | - | |
| 1966 | + | |
1984 | 1967 | | |
1985 | 1968 | | |
1986 | 1969 | | |
1987 | 1970 | | |
1988 | | - | |
| 1971 | + | |
1989 | 1972 | | |
1990 | 1973 | | |
1991 | 1974 | | |
1992 | | - | |
| 1975 | + | |
1993 | 1976 | | |
1994 | 1977 | | |
1995 | 1978 | | |
| |||
2023 | 2006 | | |
2024 | 2007 | | |
2025 | 2008 | | |
2026 | | - | |
| 2009 | + | |
2027 | 2010 | | |
2028 | 2011 | | |
2029 | 2012 | | |
| |||
2033 | 2016 | | |
2034 | 2017 | | |
2035 | 2018 | | |
2036 | | - | |
| 2019 | + | |
2037 | 2020 | | |
2038 | 2021 | | |
2039 | 2022 | | |
| |||
2122 | 2105 | | |
2123 | 2106 | | |
2124 | 2107 | | |
2125 | | - | |
| 2108 | + | |
2126 | 2109 | | |
2127 | 2110 | | |
2128 | 2111 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
487 | 487 | | |
488 | 488 | | |
489 | 489 | | |
490 | | - | |
491 | 490 | | |
492 | 491 | | |
493 | | - | |
494 | 492 | | |
495 | 493 | | |
496 | 494 | | |
| |||
501 | 499 | | |
502 | 500 | | |
503 | 501 | | |
504 | | - | |
505 | | - | |
506 | | - | |
507 | | - | |
508 | | - | |
509 | | - | |
510 | | - | |
511 | | - | |
512 | | - | |
513 | | - | |
514 | | - | |
515 | | - | |
516 | | - | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
517 | 505 | | |
518 | 506 | | |
519 | 507 | | |
| |||
547 | 535 | | |
548 | 536 | | |
549 | 537 | | |
550 | | - | |
551 | | - | |
552 | | - | |
553 | 538 | | |
554 | 539 | | |
555 | 540 | | |
| |||
567 | 552 | | |
568 | 553 | | |
569 | 554 | | |
570 | | - | |
571 | | - | |
572 | | - | |
573 | 555 | | |
574 | 556 | | |
575 | 557 | | |
| |||
602 | 584 | | |
603 | 585 | | |
604 | 586 | | |
| 587 | + | |
605 | 588 | | |
606 | | - | |
607 | | - | |
608 | | - | |
609 | | - | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
610 | 593 | | |
611 | 594 | | |
612 | 595 | | |
| |||
0 commit comments