-
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
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 |
|---|---|---|
|
|
@@ -59,8 +59,8 @@ config :logger, :default_formatter, | |
| format: "$time $metadata[$level] $message\n", | ||
| metadata: [:request_id] | ||
|
|
||
| # Use Jason for JSON parsing in Phoenix | ||
| config :phoenix, :json_library, Jason | ||
| # Use built-in `JSON` for JSON parsing in Phoenix | ||
| config :phoenix, :json_library, JSON | ||
|
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. I think here we could do a similar runtime detection as in https://github.com/phoenixframework/phoenix/pull/6481/changes#r2356177940, and only configure Same for the umbrella app config template.
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. It's a nice idea, yet I don't think it would fly. The first option is to check Elixir version during The second option is to embed this check into new projects. Technically it should work, but I'm not sure that such checks are awkward and probably are not something you would like to see in new projects. |
||
|
|
||
| # Import environment specific config. This must remain at the bottom | ||
| # of this file so it overrides the configuration defined above. | ||
|
|
||
| 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.