Skip to content

Conversation

mbland
Copy link
Contributor

@mbland mbland commented Aug 13, 2018

With these changes, the current test suite runs O(0.2s-0.3s) faster on a Mid 2015 Macbook Pro with a 2.5GHz Intel Core i7 with 16GB RAM. Not all of the optimizations have the same degree of impact, but all make the code a little less complex and a bit more readable.

Most notably, there is now only the BATS_STACK_TRACE variable, rather than BATS_CURRENT_STACK_TRACE, BATS_PREVIOUS_STACK_TRACE, and BATS_ERROR_STACK_TRACE. The only difference between the two previous stacks was the line number of the frame at the top of each. The stack trace is captured both before a command runs and after it triggers the ERR or EXIT trap. Depending on the Bash version or type of error, the BASH_LINENO would change when capturing the second stack trace. We now manage that difference via BATS_LINENO and BATS_CURRENT_LINENO.

Note that these timings are a little different than the ones in the commit messages, since I rebooted the machine before collecting these in order to ensure there was as little interference as possible from other processes and memory pressure.

Bash 3.2.57(1)-release before:

  real    0m6.532s
  user    0m3.351s
  sys     0m1.939s

Bash 3.2.57(1)-release after:

  real    0m6.223s
  user    0m3.046s
  sys     0m1.934s

Bash 4.2.23(1)-release before:

  real    0m6.893s
  user    0m3.290s
  sys     0m2.069s

Bash 4.2.23(1)-release after:

  real    0m6.660s
  user    0m3.081s
  sys     0m2.053s

Bland, Mike added 4 commits August 11, 2018 17:52
Neither of these variables were used anywhere else. Removing the
functions that assigned them shaved O(0.2s) off of the running time of
the entire suite on a Mid 2015 Macbook Pro with a 2.5GHz Intel Core i7
with 16GB RAM.

Bash 3.2.57(1)-release before:

  real    0m6.959s
  user    0m3.259s
  sys     0m1.941s

Bash 3.2.57(1)-release after:

  real    0m6.730s
  user    0m3.072s
  sys     0m1.921s

Bash 4.4.23(1)-release before:

  real    0m7.309s
  user    0m3.197s
  sys     0m2.064s

Bash 4.4.23(1)-release after:

  real    0m7.127s
  user    0m3.060s
  sys     0m2.047s
Eliminating some conditionals, the `frame` variable, and comparing the
`test_file` and `funcname` values directly resulted in an O(0.1s)
reduction in the running time of the entire suite on a Mid 2015 Macbook
Pro with a 2.5GHz Intel Core i7 with 16GB RAM.

Bash 3.2.57(1)-release before:

  real    0m6.544s
  user    0m3.157s
  sys     0m1.988s

Bash 3.2.57(1)-release after:

  real    0m6.437s
  user    0m3.057s
  sys     0m1.985s

Bash 4.2.23(1)-release before:

  real    0m6.950s
  user    0m3.150s
  sys     0m2.114s

Bash 4.2.23(1)-release after:

  real    0m6.822s
  user    0m3.097s
  sys     0m2.091s
This improves the execution time only slightly, but reduces the complexity of
the code by managing only one BATS_STACK_TRACE. We use BATS_LINENO to account
for cases where BASH_LINENO isn't handled consistently between Bash versions, or
when it's reset in the presence of unbound variable access errors.

All relevant variables are now created in bats_perform_test as well.
This provides a very slight optimization over the original API, but
makes the code a little bit cleaner.
@mbland mbland self-assigned this Aug 13, 2018
@mbland mbland requested a review from a team August 13, 2018 00:42
@ghost ghost added the review label Aug 13, 2018
@mbland mbland mentioned this pull request Aug 13, 2018
2 tasks
@mbland mbland requested review from jasonkarns and sublimino August 14, 2018 13:48
@mbland
Copy link
Contributor Author

mbland commented Aug 19, 2018

Merging this now to get things moving; per usual, comment or open a new issue if any of these changes provide cause for concern.

@mbland mbland merged commit e1e6f8d into master Aug 19, 2018
@ghost ghost removed the review label Aug 19, 2018
@mbland mbland deleted the stack-capture branch August 19, 2018 19:26
mbland pushed a commit that referenced this pull request Aug 19, 2018
Note that this commit also extracts the `bats_emit_trace` function and
makes use of variables introduced by #138.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant