Skip to content

Skip calling configure if there are no options - #664

Merged
byroot merged 1 commit into
ruby:masterfrom
eregon:skip-configure-if-no-options
Oct 30, 2024
Merged

byroot merged 1 commit into
ruby:masterfrom
eregon:skip-configure-if-no-options

Conversation

@eregon

@eregon eregon commented Oct 30, 2024

Copy link
Copy Markdown
Member
  • Set all defaults in the constructor.
  • Order the instance variables in the same order as in #configure.

Unfortunately because of JSON.dump_default_options this fast path won't apply for JSON.dump.
I wish those values (max_nesting: false, allow_nan: true) would be the default for all generate/dump-like methods and then they could be default in the State constructor.

* Set all defaults in the constructor.
* Order the instance variables in the same order as in #configure.
@eregon
eregon requested a review from byroot October 30, 2024 14:22
@eregon

eregon commented Oct 30, 2024

Copy link
Copy Markdown
Member Author

Maybe we could store the default state for JSON.dump in a constant and then .dup it, to avoid calling configure which seems particularly slow/heavy.
Kind of similar to the current const_set :FAST_STATE_PROTOTYPE, create_fast_state.
However that wouldn't respect mutations (JSON.dump_default_options[...] = ...) or reassignments (JSON.dump_default_options = { ... }).
If we don't support direct mutation and freeze the Hash then we could still compare JSON.dump_default_options by identity and cache.

Though obviously any global state seems bad and maybe the best is to deprecate JSON.dump_default_options entirely.

@byroot
byroot merged commit 6d3b3ac into ruby:master Oct 30, 2024
@byroot

byroot commented Oct 30, 2024

Copy link
Copy Markdown
Member

Yeah, I toyed with this idea too last week, and JSON.dump_default_options is indeed the blocker.

I did however managed to avoid allocating the State object entirely in #662 so it's less of a problem now.

@eregon
eregon deleted the skip-configure-if-no-options branch October 30, 2024 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants