Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance(node-fetch): make ReadableStream[Symbol.asyncIterator] AsyncIterableIterator rather than AsyncIterator only #1961

Merged
merged 1 commit into from
Jan 10, 2025

Conversation

ardatan
Copy link
Owner

@ardatan ardatan commented Jan 10, 2025

ReadableStream's Symbol.asyncIterator now returns AsyncIterableIterator like before even if it
is ok to return AsyncIterator.
It is safer to return AsyncIterableIterator because it is a common mistake to use AsyncIterator as AsyncIterable.

Copy link
Contributor

@benchmarks/node-fetch results (consumeBody)

   ✓ active_handles.................: avg=140.117193 min=13     med=140     max=197     p(90)=160     p(95)=164    
     data_received..................: 21 MB  708 kB/s
     data_sent......................: 14 MB  454 kB/s
     http_req_blocked...............: avg=2.4µs      min=661ns  med=1.21µs  max=18.79ms p(90)=1.98µs  p(95)=2.21µs 
     http_req_connecting............: avg=512ns      min=0s     med=0s      max=4.31ms  p(90)=0s      p(95)=0s     
     http_req_duration..............: avg=21.52ms    min=2.84ms med=20.92ms max=1.12s   p(90)=26.9ms  p(95)=28.78ms
       { expected_response:true }...: avg=21.52ms    min=2.84ms med=20.92ms max=1.12s   p(90)=26.9ms  p(95)=28.78ms
     http_req_failed................: 0.00%  ✓ 0           ✗ 138902
     http_req_receiving.............: avg=34.21µs    min=8.86µs med=22.6µs  max=14.96ms p(90)=36.51µs p(95)=43.29µs
     http_req_sending...............: avg=10.77µs    min=3.11µs med=5.77µs  max=18.19ms p(90)=9.39µs  p(95)=12.96µs
     http_req_tls_handshaking.......: avg=0s         min=0s     med=0s      max=0s      p(90)=0s      p(95)=0s     
     http_req_waiting...............: avg=21.48ms    min=2.77ms med=20.89ms max=1.12s   p(90)=26.85ms p(95)=28.72ms
     http_reqs......................: 138902 4629.274567/s
     iteration_duration.............: avg=43.16ms    min=9.87ms med=41.56ms max=1.14s   p(90)=47.43ms p(95)=52.62ms
     iterations.....................: 69424  2313.737437/s
     vus............................: 71     min=71        max=100 
     vus_max........................: 100    min=100       max=100 

Copy link
Contributor

@benchmarks/node-fetch results (noConsumeBody)

   ✓ active_handles.................: avg=139.797006 min=28      med=139     max=187     p(90)=161     p(95)=169    
     data_received..................: 22 MB  741 kB/s
     data_sent......................: 14 MB  480 kB/s
     http_req_blocked...............: avg=4.04µs     min=631ns   med=1.38µs  max=6.77ms  p(90)=2.02µs  p(95)=2.31µs 
     http_req_connecting............: avg=2.22µs     min=0s      med=0s      max=6.52ms  p(90)=0s      p(95)=0s     
     http_req_duration..............: avg=20.56ms    min=5.28ms  med=20.01ms max=1.07s   p(90)=25.99ms p(95)=27.53ms
       { expected_response:true }...: avg=20.56ms    min=5.28ms  med=20.01ms max=1.07s   p(90)=25.99ms p(95)=27.53ms
     http_req_failed................: 0.00%  ✓ 0           ✗ 145400
     http_req_receiving.............: avg=32.44µs    min=9.07µs  med=22.56µs max=16.63ms p(90)=36.65µs p(95)=43.65µs
     http_req_sending...............: avg=11.36µs    min=3.26µs  med=6.38µs  max=14.64ms p(90)=9.55µs  p(95)=13.2µs 
     http_req_tls_handshaking.......: avg=0s         min=0s      med=0s      max=0s      p(90)=0s      p(95)=0s     
     http_req_waiting...............: avg=20.52ms    min=5.19ms  med=19.98ms max=1.07s   p(90)=25.95ms p(95)=27.47ms
     http_reqs......................: 145400 4846.247305/s
     iteration_duration.............: avg=41.23ms    min=16.91ms med=39.72ms max=1.09s   p(90)=45.51ms p(95)=50.57ms
     iterations.....................: 72687  2422.690357/s
     vus............................: 100    min=100       max=100 
     vus_max........................: 100    min=100       max=100 

Copy link
Contributor

🚀 Snapshot Release (alpha)

The latest changes of this PR are available as alpha on npm (based on the declared changesets):

Package Version Info
@whatwg-node/fetch 0.10.2-alpha-20250110090158-4b55591216b8adb4146bd8c51856a062ae508033 npm ↗︎ unpkg ↗︎
@whatwg-node/node-fetch 0.7.6-alpha-20250110090158-4b55591216b8adb4146bd8c51856a062ae508033 npm ↗︎ unpkg ↗︎

Copy link
Contributor

@benchmarks/server results (native)

     ✓ no-errors
     ✓ expected-result

   ✓ checks.........................: 100.00% ✓ 202752      ✗ 0     
     data_received..................: 20 MB   679 kB/s
     data_sent......................: 8.1 MB  270 kB/s
     http_req_blocked...............: avg=1.5µs    min=911ns    med=1.26µs   max=233.53µs p(90)=2µs      p(95)=2.22µs  
     http_req_connecting............: avg=1ns      min=0s       med=0s       max=131.1µs  p(90)=0s       p(95)=0s      
     http_req_duration..............: avg=230.73µs min=177.63µs med=219.47µs max=11.28ms  p(90)=248.07µs p(95)=259.71µs
       { expected_response:true }...: avg=230.73µs min=177.63µs med=219.47µs max=11.28ms  p(90)=248.07µs p(95)=259.71µs
     http_req_failed................: 0.00%   ✓ 0           ✗ 101376
     http_req_receiving.............: avg=26.31µs  min=13.95µs  med=24.54µs  max=2.9ms    p(90)=31.6µs   p(95)=34.54µs 
     http_req_sending...............: avg=6.74µs   min=4.14µs   med=6.04µs   max=440.17µs p(90)=8.52µs   p(95)=9.59µs  
     http_req_tls_handshaking.......: avg=0s       min=0s       med=0s       max=0s       p(90)=0s       p(95)=0s      
     http_req_waiting...............: avg=197.67µs min=151.26µs med=186.75µs max=11.21ms  p(90)=211.96µs p(95)=222.65µs
     http_reqs......................: 101376  3379.054898/s
     iteration_duration.............: avg=291.24µs min=226.14µs med=279.06µs max=11.43ms  p(90)=311.85µs p(95)=326.87µs
     iterations.....................: 101376  3379.054898/s
     vus............................: 1       min=1         max=1   
     vus_max........................: 1       min=1         max=1   

Copy link
Contributor

@benchmarks/server results (ponyfill)

     ✓ no-errors
     ✓ expected-result

   ✓ checks.........................: 100.00% ✓ 299458      ✗ 0     
     data_received..................: 30 MB   983 kB/s
     data_sent......................: 12 MB   399 kB/s
     http_req_blocked...............: avg=1.36µs   min=872ns    med=1.16µs   max=194µs    p(90)=1.85µs   p(95)=2.01µs  
     http_req_connecting............: avg=0ns      min=0s       med=0s       max=127.92µs p(90)=0s       p(95)=0s      
     http_req_duration..............: avg=138.2µs  min=93.88µs  med=133.73µs max=5.89ms   p(90)=155.53µs p(95)=162.36µs
       { expected_response:true }...: avg=138.2µs  min=93.88µs  med=133.73µs max=5.89ms   p(90)=155.53µs p(95)=162.36µs
     http_req_failed................: 0.00%   ✓ 0           ✗ 149729
     http_req_receiving.............: avg=24.33µs  min=12.22µs  med=22.9µs   max=2.4ms    p(90)=29.98µs  p(95)=32.62µs 
     http_req_sending...............: avg=6.25µs   min=4.01µs   med=5.42µs   max=279.45µs p(90)=8.07µs   p(95)=8.66µs  
     http_req_tls_handshaking.......: avg=0s       min=0s       med=0s       max=0s       p(90)=0s       p(95)=0s      
     http_req_waiting...............: avg=107.62µs min=66.66µs  med=102.67µs max=5.85ms   p(90)=121.6µs  p(95)=127.27µs
     http_reqs......................: 149729  4990.760574/s
     iteration_duration.............: avg=195.94µs min=139.69µs med=190.73µs max=6.07ms   p(90)=215.82µs p(95)=224.44µs
     iterations.....................: 149729  4990.760574/s
     vus............................: 1       min=1         max=1   
     vus_max........................: 1       min=1         max=1   

Copy link
Contributor

@benchmarks/server results (undici)

     ✓ no-errors
     ✓ expected-result

   ✓ checks.........................: 100.00% ✓ 215686      ✗ 0     
     data_received..................: 22 MB   723 kB/s
     data_sent......................: 8.6 MB  288 kB/s
     http_req_blocked...............: avg=1.44µs   min=872ns    med=1.23µs   max=194.14µs p(90)=1.91µs   p(95)=2.08µs  
     http_req_connecting............: avg=1ns      min=0s       med=0s       max=127.66µs p(90)=0s       p(95)=0s      
     http_req_duration..............: avg=214.06µs min=158.71µs med=203.1µs  max=56.8ms   p(90)=228.42µs p(95)=237.39µs
       { expected_response:true }...: avg=214.06µs min=158.71µs med=203.1µs  max=56.8ms   p(90)=228.42µs p(95)=237.39µs
     http_req_failed................: 0.00%   ✓ 0           ✗ 107843
     http_req_receiving.............: avg=26.3µs   min=13.9µs   med=24.85µs  max=2.19ms   p(90)=31.88µs  p(95)=34.41µs 
     http_req_sending...............: avg=6.61µs   min=4.12µs   med=5.95µs   max=295.57µs p(90)=8.27µs   p(95)=9.18µs  
     http_req_tls_handshaking.......: avg=0s       min=0s       med=0s       max=0s       p(90)=0s       p(95)=0s      
     http_req_waiting...............: avg=181.14µs min=128.25µs med=170.41µs max=56.72ms  p(90)=192.7µs  p(95)=201.06µs
     http_reqs......................: 107843  3594.617993/s
     iteration_duration.............: avg=273.54µs min=202.63µs med=261.5µs  max=56.94ms  p(90)=290.55µs p(95)=301.99µs
     iterations.....................: 107843  3594.617993/s
     vus............................: 1       min=1         max=1   
     vus_max........................: 1       min=1         max=1   

@ardatan ardatan merged commit 2785c80 into master Jan 10, 2025
24 checks passed
@n1ru4l n1ru4l deleted the async-iterable-iterator branch January 10, 2025 09:33
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