-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Use the built-in JSON library #6481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
7a74e4d
802a479
006941d
41d3c0d
16e96f6
9122de9
17cc255
384cccb
a7c164f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,8 @@ defmodule Phoenix do | |
| """ | ||
| use Application | ||
|
|
||
| @default_json_library if Code.ensure_loaded?(JSON), do: JSON, else: Jason | ||
|
|
||
| @doc false | ||
| def start(_type, _args) do | ||
| # Warm up caches | ||
|
|
@@ -45,7 +47,7 @@ defmodule Phoenix do | |
|
|
||
| """ | ||
| def json_library do | ||
| Application.get_env(:phoenix, :json_library, Jason) | ||
| Application.get_env(:phoenix, :json_library, @default_json_library) | ||
|
SteffenDE marked this conversation as resolved.
Outdated
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider :persistent_term, which is roughly 30-100% faster: defmodule JSON.Adapter do
@default_json_library if Code.ensure_loaded?(JSON), do: JSON, else: Jason
def json_library do
case :persistent_term.get(:json_library, nil) do
nil ->
module = :application.get_env(:phoenix, :json_library, @default_json_library)
:persistent_term.put(:json_library, module)
module
module ->
module
end
end
end
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TIL |
||
| end | ||
|
|
||
| @doc """ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.