Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions simple_seismic_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ def do_GET(self):

def send_json(self, data):
self.send_response(200)
self.send_header('Content-Type', 'application/json')
self.send_header('Content-Type', 'application/json; charset=utf-8')
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The charset parameter is not defined for the application/json media type according to RFC 8259 (Section 11). Since JSON is required to be encoded as UTF-8 when exchanged between systems, this parameter is redundant and technically non-compliant with the specification. Removing it also aligns with the goal of minimizing payload size mentioned in the PR description.

Suggested change
self.send_header('Content-Type', 'application/json; charset=utf-8')
self.send_header('Content-Type', 'application/json')

self.send_header('Access-Control-Allow-Origin', '*')
self.end_headers()
self.wfile.write(json.dumps(data, separators=(',', ':')).encode())
self.wfile.write(json.dumps(data, separators=(',', ':')).encode('utf-8'))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To further optimize performance and reduce payload size, consider adding ensure_ascii=False to the json.dumps call. By default, json.dumps escapes non-ASCII characters (e.g., \uXXXX), which is more CPU-intensive and results in larger output than literal UTF-8 characters. Since the output is explicitly encoded as UTF-8, allowing literal characters is more efficient.

Additionally, please note that the separators=(',', ':') argument was already present in the code before this change. The primary performance gains described in the PR (5.04x speedup) likely refer to the removal of indent=2, which is not visible in this diff hunk.

Suggested change
self.wfile.write(json.dumps(data, separators=(',', ':')).encode('utf-8'))
self.wfile.write(json.dumps(data, separators=(',', ':'), ensure_ascii=False).encode('utf-8'))


def log_message(self, format, *args):
"""Override to customize logging"""
Expand Down
Loading