question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Batch is not sound on `head` and other remarks

See original GitHub issue

Hi!

I stumbled by chance on the new Batch collection added recently in this library. After a quick look at the implementation, it exhibits a few weaknesses and at least a couple bugs. Using a single ticket to collect my thoughts on it, a PR might follow if I find the time.


Combine case is not guaranteed to have non-empty children, whereas head and headOption assume so. At the same time isEmpty indicates the implementation may allow non-empty children.

This test fails:

assert(Batch(Batch.Empty, Batch(1, 2, 3)).head == 1)
// java.util.NoSuchElementException: Batch.Empty.head

Two approaches:

  • (a) ensure the children of Combine are never empty by using the ++ everywhere. Can be error-prone but simple enough to implement, might be worth adding implementation comments on the design decision. Will make the isEmpty always false.
  • (b) allow empty children and fix head and headOption accordingly.

The mkString throws an exception on the empty cases. The mkString(" ") also adds a trailing separator in the case of single element, which is not expected?

Failing tests:

test("mkString") {
  assert(Batch.Empty.mkString == "")
  assert(Batch(1).mkString(" ") == "1")
}

The memoization in _jsArray is simple enough, but a bit arbitrary as some methods will use it, and some won’t. It could be interesting to try to leverage this memoization in the Wrapped and Combine cases, actually making sure it’s computed only once and short-circuiting all the methods on it. To simplify the Batch implementation it could also be an option to drop the Empty and Singleton (replaced with Wrapped), without any performance impact.


The catch { _ => false } fallback in equality check is not idiomatic and may have serious performance impact.


I am not sure on how js.Array is implemented, but the unapply on :: might have misleading performance, splitting the array over and over again in the tail?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
lomigmegardcommented, Jun 11, 2022

Hey thanks for the quick reply, Saturday is definitely for side projects 😄

Your listed goals make total sense for sure! And I will open dedicated issues and tasks if I find the time to work on them a bit more, it’s easier to show what I meant with some draft code.

Cheers

0reactions
davesmith00000commented, Jul 14, 2022

I believe I’ve answered most of this in the work that is now in main, very helpful - thank you! Would be happy to re-open if you think I’ve missed anything or address individual issues on a case by case basis.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Auditory processing disorder - when the brain can't process ...
Auditory processing disorder (APD ) is a condition where the brain doesn't properly translate the meaning of sounds.
Read more >
Richard L Hess—Audio Tape Restoration Tips & Notes
The worse of the two tapes was stopped twice to re-clean the heads and reapply D5. It is not clear to me if...
Read more >
How to Batch Sync Audio in Premiere Pro in Five Easy Steps
Cut the empty spaces. Trim to head and tail. Make sure you've got MONO audio clips sitting in MONO audio tracks. No exceptions...
Read more >
XMLUserGuide_FinCENSAR.pdf - BSA E-Filing System
This element must be recorded if the parent element is recorded” to “Record this element for the Branch (46) where activity occurred party...
Read more >
Can't hear caller or caller can't hear agent? - Amazon Connect
Go to Device Manager, then expand Audio inputs and outputs. If your computer recognizes your headset, you'll see it listed there.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found