GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — for ... of replacing for(;;) in library networking code? · Issue #31024 · nodejs/node

for ... of replacing for(;;) in library networking code? #31024

New issue
Copy link
New issue
Copy link
Closed
Closed
for ... of replacing for(;;) in library networking code?#31024
Copy link

Description

@edgework
edgework
opened on Dec 19, 2019
Issue body actions

Why was [https://github.com//pull/30958] approved and released in 13.5? It has no real justification and actually has a performance impact. for(;;) will always be the fasted loop.

Reacted by Ferdi, pxDot, Tijs De Belie, Nayef, Yiğit Sözer and Linz
Reacted by Ruben Bridgewater

Activity

  1. trivikr commented on Dec 19, 2019

    @trivikr
    trivikr
    on Dec 19, 2019
    Member
    More actions

    #30958 only made changes in _http_agent.js
    For other files, we added comments to retain for(;;) for performance reasons

    Commit: ddedf8e

    Reacted by edgework
  2. Lindsor commented on Dec 19, 2019

    @Lindsor
    Lindsor
    on Dec 19, 2019
    More actions

    The fact multiple files were updated with a comment saying for(;;) loops kept for performance reasons should be justification enough to not change any loops

    Reacted by Tijs De Belie, Nayef and Yiğit Sözer
    Reacted by Zach
    Reacted by Ruben Bridgewater
  3. edgework commented on Dec 19, 2019

    @edgework
    edgework
    on Dec 19, 2019
    Author
    More actions

    What was the point of this change in the first place? How did it make Node better? Its a waste of time and a performance step back regardless of how small.

    Reacted by pxDot, Tijs De Belie, Nayef, Yiğit Sözer and Ryan M.
    Reacted by arnx
    Reacted by Ruben Bridgewater
  4. Trott commented on Dec 19, 2019

    @Trott
    Trott
    on Dec 19, 2019
    Member
    More actions

    What was the point of this change in the first place? How did it make Node better?

    Arguably, it makes the code more readable and thus maintainable. Since it's in a place where there is no measurable performance impact, readability/maintainability can take precedence. Additionally, there's something to be said for favoring idiomatic code.

    There are, of course, counterarguments. Perhaps the for...of does not seem more readable to everyone but only people familiar/comfortable with that syntax. (In other words, "idiomatic" is in the eye of the beholder.) Perhaps having a mixture of for...of and for ;; in the code is confusing. And so on.

    For me, the most convincing argument against it is probably that cosmetic code changes entail risk of introducing bugs and should have a compelling reason for being introduced in lib code.

    These things are tradeoffs and reasonable people can make different decisions about them.

    (Personally, I had a mild/minuscule preference for not making the change, but with previous approvals, I'd rather approve-and-land-and-move-on than get mired in a discussion about the merits etc. The cost/benefit of the discussion isn't worth it. And if it's more readable for other folks, that's reason enough.)

    Reacted by Anna Henningsen, Trivikram Kamat, Myles Borins and Ruben Bridgewater
  5. Trott commented on Dec 19, 2019

    @Trott
    Trott
    on Dec 19, 2019
    Member
    More actions

    (Also, if the concern is just this one file, a PR changing it back to for ;; is reasonable. It may or may not land, of course. It will be easier to justify if there's a reliable and realistic benchmark to show that the change has a measurable impact on Node.js http performance, but I doubt such a benchmark can be made easily. But as long as the reversion is made with a spirit of constructive collaboration, I imagine it would get at least some support. I'm certainly OK with a "just don't do this in http code" approach, but I'm only one opinion.)

  6. BridgeAR commented on Dec 20, 2019

    @BridgeAR
    BridgeAR
    on Dec 20, 2019
    Member
    More actions

    I would like to add to the performance part:

    Loop performance is not an issue anymore as of Node.js version >= 10.x. No matter if it's for (;;), for...of or forEach(). All of those perform about the same due to V8 updates. The comment in the code was probably meant specific for streams. That part is copied 1-1 to become readable-streams which has to support older Node.js versions as well.

    But even if there is a tiny performance difference, it would not show up as a real downside for applications, since the actual code running would make up for most of the run time of the loop.

    Idiomatic code should be more important than 0.01% performance improvement. Actual performance gains are almost always possible by changing the algorithm in some way - not by using different for loops!

    Reacted by coreyc
  7. BridgeAR commented on Dec 20, 2019

    @BridgeAR
    BridgeAR
    on Dec 20, 2019
    Member
    More actions

    I say that as someone who did numerous performance optimizations in core.

  8. BridgeAR commented on Dec 20, 2019

    @BridgeAR
    BridgeAR
    on Dec 20, 2019
    Member
    More actions

    Closing. If any collaborator would like to keep this open, please feel free to do so.

  9. BridgeAR
    closed this as completedon Dec 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.