Skip to content

Conversation

@ganmacs
Copy link

@ganmacs ganmacs commented Jun 20, 2019


def read_line?
@stream.gets(CRLF, chomp: true)
@stream.gets(CRLF).chomp
Copy link
Member

Choose a reason for hiding this comment

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

The problem with this is it allocates extra strings and this breaks memory usage assumptions. I'll need to confirm this is going to work in light of the memory limit specs we have.

Copy link
Author

Choose a reason for hiding this comment

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

I checked and result is here https://gist.github.com/ganmacs/52fbcabdc1311d43dcd730442672a7a9.

The problem with this is it allocates extra strings and this breaks memory usage assumptions

it's certainly so but, @stream.gets(CRLF, chomp: true) creates a new Hash instance and it allocates more memory than @stream.gets(CRLF).chomp ver.

Copy link
Member

@ioquatix ioquatix Jun 20, 2019

Choose a reason for hiding this comment

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

Yes, you are right, at the time I considered this.

Fortunately, it only allocates a hash when @stream is actually a Ruby IO instance. However, for Async::IO::Stream because gets is pure Ruby, it doesn't allocate a hash. It's very tricky to get right and I agree it's kind of crappy edge case.

I'm happy to work on supporting 2.3 as a baseline, but I just need to review how the entire thing fits together. It might even be the case that we just version detect, e.g. if RUBY_VERSION <= "2.3" use .chomp

Copy link
Member

Choose a reason for hiding this comment

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

In pure ruby implementation of streams, @stream.gets(CRLF, chomp: true) is more efficient too.

Copy link
Author

Choose a reason for hiding this comment

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

e.g. if RUBY_VERSION <= "2.3" use .chomp

if you are okay with it. i'm ok too 👍
43802f0

the following implementation is the best, but it will block and never
return. I don't know why it's occured...

```
class IO
  def gets(*args, chomp: false)
    chomp ? super(*args).chomp : super(*args)
  end
end
```
@ganmacs
Copy link
Author

ganmacs commented Jun 28, 2019

@ioquatix what do you think of this code?

@ioquatix
Copy link
Member

ioquatix commented Jul 9, 2019

I did this in a way which allowed me to keep the code isolated and easy to remove in the future. Thanks for this PR and the related discussion, and your efforts. Please keep it coming!

@ioquatix ioquatix closed this Jul 9, 2019
@ioquatix
Copy link
Member

ioquatix commented Jul 9, 2019

I also reviewed protocol-http and it seems okay, I need to check protocol-http2.

@ganmacs ganmacs deleted the support-2.3 branch July 10, 2019 02:34
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