Skip to content

Conversation

@mertcanaltin
Copy link
Member

@mertcanaltinmertcanaltin commented Apr 15, 2023

Use ASCII instead of Latin1 as encoding. ASCII is a subset of Latin1 and provides better compatibility across different systems and platforms @mcollina@ronag#57

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/http
  • @nodejs/net

@nodejs-github-botnodejs-github-bot added http Issues or PRs related to the http subsystem. needs-ci PRs that need a full CI run. labels Apr 15, 2023
@mertcanaltinmertcanaltin changed the title dev: merge HTTP chunks during chunked encoding #57dev: merge HTTP chunks during chunked encodingApr 15, 2023
if(msg.chunkedEncoding&&chunk.length!==0){
len??=typeofchunk==='string' ? Buffer.byteLength(chunk,encoding) : chunk.byteLength;
msg._send(NumberPrototypeToString(len,16),'latin1',null);
msg._send(NumberPrototypeToString(len,16),'ascii',null);
Copy link
Contributor

@mscdexmscdexApr 15, 2023

Choose a reason for hiding this comment

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

I think we shouldn't change this as this will incur unnecessary overhead as node has to parse the string to ensure it's valid ASCII (and we know it will already be valid because we're using the built-in Number.prototype.toString()). latin1 doesn't have such overhead since it's a single byte encoding.

Copy link
Member

Choose a reason for hiding this comment

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

I'm confused. ASCI is also single byte

Copy link
Member

Choose a reason for hiding this comment

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

Where/Why is there an overhead?

Copy link
Member

Choose a reason for hiding this comment

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

Though I do see now that the change is probably unnecessary.

Copy link
Member

Choose a reason for hiding this comment

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

We are a bit inconsistent when we use ascii and when we use latin1.

Copy link
Member

Choose a reason for hiding this comment

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

Where/Why is there an overhead?

With 'ascii' node checks for every byte it's within the range 0-127 inclusive. With 'latin1' there's no such check.

O(n) vs. O(0), basically. :-)

@ronag
Copy link
Member

The name of the PR and commit is misleading

Copy link
Member

@ronagronag left a comment

Choose a reason for hiding this comment

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

@ronagronag closed this Apr 16, 2023
@mertcanaltin
Copy link
MemberAuthor

thank you for answers

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

httpIssues or PRs related to the http subsystem.needs-ciPRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@mertcanaltin@nodejs-github-bot@ronag@mscdex@bnoordhuis