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

Performance improvements for Hashtables, ForEach, and Where-Object #258

Closed
Badgerati opened this issue May 20, 2019 · 4 comments · Fixed by #260
Closed

Performance improvements for Hashtables, ForEach, and Where-Object #258

Badgerati opened this issue May 20, 2019 · 4 comments · Fixed by #260

Comments

@Badgerati
Copy link
Owner

This issue is change the way certain functions work in Pode, to aid in improving its performance. All the following changes are quicker, and although in small cases they're negligible it could still matter for large files or hundreds of rapid requests.

The following changes are to be applied to code that gets called on web requests; general logic on initial server start isn't mandatory as it's called once.

  • All references to ForEach-Object to be replaced with a normal foreach loop.
  • All references to Where-Object to be replaced with a foreach loop with an if statement.
  • All hashtable property references to be changed to indexing: $ht[$key] = $value
@Badgerati
Copy link
Owner Author

Badgerati commented May 21, 2019

Another speed improvements:

  • Change all $array | Select-Object -First 1 to $array[0] - but protect again nulls.
    • And also -Last 1 to $array[$array.Length - 1]
  • Change Measure-Object to Pode's Get-PodeCount

@Badgerati
Copy link
Owner Author

Ran some performance tests over the branch with the changes, and the current develop branch; and looks quite good.

develop:

checks.....................: 100.00% ✓ 13016 ✗ 0
http_req_duration..........: avg=91.88ms min=54.99ms med=88.01ms max=222.05ms p(90)=106.01ms p(95)=119.03ms
http_reqs..................: 6508    108.464655/s
iteration_duration.........: avg=92.07ms min=57ms    med=88.02ms max=222.05ms p(90)=106.17ms p(95)=119.52ms
iterations.................: 6508    108.464655/s

Issue-258:

checks.....................: 100.00% ✓ 15608 ✗ 0
http_req_duration..........: avg=76.62ms min=16ms    med=76.01ms max=196.02ms p(90)=82.01ms p(95)=84.01ms
http_reqs..................: 7804    130.065655/s
iteration_duration.........: avg=76.8ms  min=18.99ms med=76.01ms max=197.02ms p(90)=82.01ms p(95)=84.02ms
iterations.................: 7804    130.065655/s

@jeremymcgee73
Copy link

Awesome! Good job!

@Badgerati
Copy link
Owner Author

Continuing with the changes I've also:

  • Modified Test-Empty to used -is rather than .GetType(). (doubles the functions performance)
    • Ie: Checking a string is down from 20ms to 10ms
  • Updated any string checks to use [string]::IsNullOrWhiteSpace(..) (drastically increases performance)
  • Updated array checks to directly check $null and .Length (same increase as strings)

With this, here's the new stats:

checks.....................: 100.00% ✓ 20252 ✗ 0
http_req_duration..........: avg=58.94ms min=10ms    med=57ms max=134ms  p(90)=66.99ms p(95)=71ms
http_reqs..................: 10126   168.761103/s
iteration_duration.........: avg=59.12ms min=11.97ms med=57ms max=134ms  p(90)=67ms    p(95)=71.99ms
iterations.................: 10126   168.761103/s

@Badgerati Badgerati added this to the 0.30.0 milestone May 23, 2019
Badgerati added a commit that referenced this issue May 23, 2019
Badgerati added a commit that referenced this issue May 23, 2019
Resolves #258 - Performance increases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants