Skip to content

Commit

Permalink
Merge 28e0442 into 8f9a07a
Browse files Browse the repository at this point in the history
  • Loading branch information
cblage committed Apr 13, 2018
2 parents 8f9a07a + 28e0442 commit aa74f38
Show file tree
Hide file tree
Showing 143 changed files with 1,445 additions and 17,463 deletions.
5 changes: 5 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: "2"
plugins:
credo:
enabled: true
channel: "beta"
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@ erl_crash.dump
# Also ignore archive artifacts (built via "mix archive.build").
*.ez

<<<<<<< 26cc7c1a7c0e718707208ab099d9d87efb8925e8
=======
# Ignore benchmark output
#/bench/output
/bench/snapshots
>>>>>>> bench
15 changes: 13 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
env:
global:
- CC_TEST_REPORTER_ID=a669f9b84dcb893c8df72d85c56658c03e59c523ef619714d37b6523d35698aa
language: elixir
env: MIX_ENV=test
notifications:
recipients:
- carlos@carloslage.net
elixir:
- 1.6
before_script:
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
- chmod +x ./cc-test-reporter
- ./cc-test-reporter before-build
script:
- mix dialyzer
- MIX_ENV=test mix test
after_script:
- mix deps.get --only docs
- MIX_ENV=docs mix inch.report
- MIX_ENV=test mix coveralls --verbose
- MIX_ENV=test mix coveralls.json --verbose
- MIX_ENV=test mix coveralls.travis
- ./cc-test-reporter after-build -r "r$CC_TEST_REPORTER_ID" -t excoveralls --exit-code $TRAVIS_TEST_RESULT
after_success:
- MIX_ENV=test mix coveralls
- MIX_ENV=test mix coveralls.post --token ilbBz5SvaqJqUBZx9KcIcuM8C1D3BCsB8 --branch $TRAVIS_BRANCH --name "TravisCI"
- mix credo --strict
116 changes: 99 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,114 @@
# License
The Elixir JSON library is available under the [BSD 3-Clause aka "BSD New" license](http://www.tldrlegal.com/l/BSD3)

# Elixir JSON

[![Coverage Status](https://coveralls.io/repos/github/cblage/elixir-json/badge.svg?branch=master)](https://coveralls.io/github/cblage/elixir-json?branch=develop)
[![Hex.pm](https://img.shields.io/hexpm/v/json.svg?style=flat-square)](https://hex.pm/packages/json)
[![Build Status](https://travis-ci.org/cblage/elixir-json.svg?branch=master)](https://travis-ci.org/cblage/elixir-json) [![Inline docs](http://inch-ci.org/github/cblage/elixir-json.svg)](http://inch-ci.org/github/cblage/elixir-json)
[![Hex.pm](https://img.shields.io/hexpm/dt/json.svg?style=flat-square)](https://hex.pm/packages/json)


[![Hex.pm](https://img.shields.io/hexpm/dt/json.svg?style=flat-square)](https://hex.pm/packages/json)[![Build Status](https://travis-ci.org/cblage/elixir-json.svg?branch=master)](https://travis-ci.org/cblage/elixir-json) [![Maintainability](https://api.codeclimate.com/v1/badges/43b6e8c25e036558ccb6/maintainability)](https://codeclimate.com/github/cblage/elixir-json/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/43b6e8c25e036558ccb6/test_coverage)](https://codeclimate.com/github/cblage/elixir-json/test_coverage)


[![Hex.pm](https://img.shields.io/hexpm/v/json.svg?style=flat-square)](https://hex.pm/packages/json) [![Inline docs](http://inch-ci.org/github/cblage/elixir-json.svg)](http://inch-ci.org/github/cblage/elixir-json)


This library provides a natively implemented JSON encoder and decoder for Elixir.

All contributions are welcome.
## Installing

Simply add ```{:json, "~> 1.2"}``` to your project's ```mix.exs``` file, in the dependencies list and run ```mix deps.get json```.
# Before you install

When dealing with smaller `file.json ~ 14KB` payloads, `JSON v1` handles the processing consistently performant, with
a much smaller deviation, and absolutely no real-world absolute performance differences with `Jason`.

However, with often unusually large `file.json > 5MB` payloads, and if the processing speed for those payloads is
paramount to you (ie, processing them in a real-time manner vs using them in migration scripts or whatever), `JSON v1`
currently significantly slower when compared to `Jason`.

#### Small payload `bench/data/utf-8-unescaped.json < 30KB` benchmark results for `JSON v1` and `Jason`

As you can see below, both libraries handle "regular" small `json` payloads beautifully.

`JSON.decode` calls while usually being a bit slower than their `Jason` counterparts, they are more consistently
performant, with a much smaller deviation.

So I would actually advise using `JSON.decode` and `JSON.encode` for smaller payloads.

For `JSON.encode` vs `Jason.encode`, the difference is so minimal, it's not worth arguing about.

| Library | Average | Deviation | median | minimum | maximum |
|---------------- |---------- |----------- |---------- |---------- |----------- |
| `JSON.decode` | 13.35 ms | ±45.95% | 11.47 ms | 8.17 ms | 99.49 ms |
| `Jason.decode` | 0.26 ms | ±246.84% | 0.170 ms | 0.150 ms | 64.35 ms |
| `JSON.encode` | 1.32 ms | ±225.81% | 0.58 ms | 0.28 ms | 103.70 ms |
| `Jason.encode` | 0.30 ms | ±316.71% | 0.163 ms | 0.147 ms | 82.68 ms |

#### Full `benchee` reports for `bench/data/utf-8-unescaped.json < 30KB`:
- `decode`: https://bit.ly/2GVV8dy
- `encode`: https://bit.ly/2v5W0H0


#### Large payload `bench/data/issue-90.json ~ 8MB` benchmark results for `JSON v1` and `Jason`

However, with often unusually large `file.json > 5MB` payloads, and if the processing speed for those payloads is paramount to you
(ie, processing them in a real-time manner vs using them in migration scripts or whatever), then
`JSON v1` would not be the best choice when compared to `Jason`.

| Library | Average | Deviation | median | minimum | maximum |
|---------------- |---------- |----------- |---------- |---------- |----------- |
| `JSON.decode` | 8.93 s | ±5.71% | 8.96 s | 8.10 s | 9.57 s |
| `Jason.decode` | 0.182 s | ±21.60% | 0.171 s | 0.139 s | 0.42 s |
| `JSON.encode` | 5.51 s | ±18.10% | 5.24 s | 4.32 s | 7.36 s |
| `Jason.encode` | 0.186 s | ±26.41% | 0.173 s | 0.122 s | 0.38 s |

### Full `benchee` reports for `bench/data/issue-90.json ~ 8MB`:
- `decode`: https://bit.ly/2HxReEP
- `encode`: https://bit.ly/2HuR0OM

# Plan of action for `Elixir JSON v2`

I am currently working on a solution for this problem in `JSON v2`.
You can follow the process here: https://github.com/cblage/elixir-json/pull/52

# Interim Solution

To processes these large payloads adding the `Jason` lib to your dependencies (without hopefully removing `JSON`
for the smaller payloads :sweat_smile:):
- `Jason@Hex.pm`: http://hex.pm/packages/jason
- `Jason@GitHub`: https://github.com/michalmuskala/jason

After installing `Jason`, you then use `JSON.decode` and `JSON.encode` for small your small `30KB range json` payloads due to the reasons mentioned above.

While `Elixir JSON v2` is not ready to processs the bigger `>5MB json` payloads in time-sensitive operations, you go for `Jason.decode` and `Jason.encode`.

Thanks for the comprehension,
Carlos Brito Lage

## Example

### Example for a project that already uses [Plug](https://github.com/elixir-plug/plug):
```elixir
defp deps do
[{:cowboy, "~> 1.0.0"},
[
{:cowboy, "~> 1.0.0"},
{:plug, "~> 1.0"},
{:json, "~> 1.2"}]
end
{:json, "~> 1.2"},
{:jason, "~> 1.0"},
]
```

You can find its documentation here: https://hexdocs.pm/jason/readme.html

#Installing

Simply add ```{:json, "~> 1.2"}``` to your project's ```mix.exs``` file, in the dependencies list and run ```mix deps.get json```.

## Example for a project that already uses [Plug](https://github.com/elixir-plug/plug):

```elixir
[
{:cowboy, "~> 1.0.0"},
{:plug, "~> 1.0"},
{:json, "~> 1.2"},
]
```

## Usage
# Usage

Encoding an Elixir type
```elixir
Expand Down Expand Up @@ -54,6 +139,3 @@ Decoding a list from a string that contains JSON
list["key"]
# "this will be a value"
```

## License
The Elixir JSON library is available under the [BSD 3-Clause aka "BSD New" license](http://www.tldrlegal.com/l/BSD3)
10 changes: 5 additions & 5 deletions bench/decode.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
decode_jobs = %{
"Jason" => fn {json, _} -> Jason.decode!(json) end,
#"Poison" => fn {json, _} -> Poison.decode!(json) end,
"JSX" => fn {json, _} -> JSX.decode!(json, [:strict]) end,
#"JSX" => fn {json, _} -> JSX.decode!(json, [:strict]) end,
#"Tiny" => fn {json, _} -> Tiny.decode!(json) end,
#"jsone" => fn {json, _} -> :jsone.decode(json) end,
"JSON" => fn {json, _} -> JSON.decode!(json) end,
Expand All @@ -12,11 +12,11 @@ decode_inputs = [
#"GitHub",
#"Giphy",
#"GovTrack",
"Blockchain",
#"Blockchain",
#"Pokedex",
"JSON Generator",
"JSON Generator (Pretty)",
"UTF-8 escaped",
#"JSON Generator",
#"JSON Generator (Pretty)",
#"UTF-8 escaped",
"UTF-8 unescaped",
"Issue 90",
]
Expand Down
20 changes: 10 additions & 10 deletions bench/encode.exs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
encode_jobs = %{
"Jason" => &Jason.encode_to_iodata!/1,
"Jason strict" => &Jason.encode_to_iodata!(&1, maps: :strict),
"Poison" => &Poison.encode_to_iodata!/1,
"JSX" => &JSX.encode!/1,
#"Jason strict" => &Jason.encode_to_iodata!(&1, maps: :strict),
#"Poison" => &Poison.encode_to_iodata!/1,
#"JSX" => &JSX.encode!/1,
#"Tiny" => &Tiny.encode!/1,
#"jsone" => &:jsone.encode/1,
"JSON" => &JSON.encode!/1,
"term_to_binary" => &:erlang.term_to_binary/1,
#"term_to_binary" => &:erlang.term_to_binary/1,
}

encode_inputs = [
"GitHub",
"Giphy",
"GovTrack",
"Blockchain",
"Pokedex",
"JSON Generator",
#"GitHub",
#"Giphy",
#"GovTrack",
#"Blockchain",
#"Pokedex",
#"JSON Generator",
"UTF-8 unescaped",
"Issue 90",
]
Expand Down
12 changes: 0 additions & 12 deletions bench/output/assets/fontello/LICENSE.txt

This file was deleted.

43 changes: 0 additions & 43 deletions bench/output/assets/fontello/css/fontello.css

This file was deleted.

0 comments on commit aa74f38

Please sign in to comment.