[wp-trac] [WordPress Trac] #24152: Use JSON as alternative to headers

WordPress Trac noreply at wordpress.org
Sat Oct 10 01:17:08 UTC 2015


#24152: Use JSON as alternative to headers
-----------------------------+------------------------------
 Reporter:  ryanve           |       Owner:
     Type:  feature request  |      Status:  reopened
 Priority:  normal           |   Milestone:  Awaiting Review
Component:  Themes           |     Version:
 Severity:  normal           |  Resolution:
 Keywords:  close            |     Focuses:
-----------------------------+------------------------------

Comment (by nacin):

 Replying to [comment:17 swalkinshaw]:
 > * '''Performance''': I haven't seen this mentioned before, but the
 current file headers parsing is quite slow due to regular expression
 usage. I made a ''very'' simple micro-benchmark to parse the exact same
 headers with the current WP method and also with `json_decode` and
 `parse_ini_file`. This benchmark just does 10000 iterations of the
 parsing.
 >
 > Results:
 >
 > * `get_file_data`: 1.98s
 > * `json_decode`: 218ms
 > * `parse_ini_file`: 482ms

 Are these numbers based on the average or the sum of 10000 iterations?

 I'd identify one problem with these benchmarks. `get_file_data()` and
 `parse_ini_file()` both hit the filesystem. `json_decode()` does not. If
 you didn't account for that, well, that I/O hit is pretty significant. If
 you did account for it, then I'd suggest that benchmarking this at high
 iterations isn't all that useful, since it'd only ever be run a few times
 on a pageload anyway.

 > * '''Dependencies''': As mentioned above, a metadata file would allow
 for more flexibility for features like dependencies. Without it, a feature
 like that will probably never happen.

 I think this is a cart before the horse. I am not sure the form in which
 dependencies will happen, but if it's determined we need something like
 this, then we'd do it. But not having this at the moment is not blocking
 any work on dependencies.

 > * '''Bugs''': The current parsing method is error prone due to using
 regular expressions. See ticket:19854 and ticket:15193.

 Those tickets are both five years old, not long after we consolidated all
 of this logic into a single `get_file_data()` function, and I've seen
 nothing to suggest we still have edge cases here.

 > * '''Uniformity''': since JSON has a spec and built-in parsers in
 basically every language, it doesn't necessarily matter how you format
 whitespace for example. But with the current file headers, there's no
 uniformity and it can cause problems. Here's an example from the bug
 above:

 I don't really have a problem with this. Only WP needs to do this parsing.

 As I indicated originally, I totally understand the desire and the use
 case. I just don't believe it is a complexity we have any need to
 introduce right now, regardless of format (json v yaml).

--
Ticket URL: <https://core.trac.wordpress.org/ticket/24152#comment:24>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list