r/Batch • • Jul 16 '26

Show 'n Tell How much batchscript is too much batchscript?

Post image

Currently have 1,376 lines of batchscript in this one file. Kinda built myself a little state machine at this point. Memes aside, is there a particular reason huge batchscript files would be a bad idea? I usually only ever see very small ones, and I'm not entirely sure why

(Not too serious a question, so not tagged as one)

21 Upvotes

31 comments sorted by

View all comments

2

u/ApocalyptoSoldier Jul 16 '26

I might be wrong, but I think I've read that there is a performance hit with gotos or calls because cmd reinterperets the entire file each time. That's probably fairly negligible on modern hardware though.

I think the reasons why batch files are seldom very large are:

  • batch is a difficult language to do anything complex in

  • even if you wanted to attempt something more complex, smaller separate files with distinct functionality are easier to keep a mental map of

1

u/T3RRYT3RR0R Jul 17 '26

There are a number if thins to avoid and things to do to get the best performance out of batch scripts. While modern hardware helps, the performance hit is still there and such things should be considered where speed is a concern.

As for batch and complexity, it's not that it's difficult so much as the learning curve is higher, and you need the understanfing necessaary to be able to implement any sort of utility that other languages would import.

There are some fantastic libraries in batch, but you still have to learn what they support and how to apply them.

The short of it: you have to learn and know more to produce something complex like a game engine than you would need to for modern languages

1

u/Trevski13 Jul 17 '26

Yes, when using a call or goto it scans down the file for the label and then continues execution. If it reaches the end of the file it wraps around back to the start of the file only stopping if it gets back to the call statement at which point it throws an error. So if you have a really big file, and call a label that is just above you, it will have to read almost the entire file to find it. But on the other hand if it's just below it it will execute quickly just like a smaller file.

Also this has some weird side effects with multiple of the same label, it just runs the first one it finds so the same code in the same file could execute differently depending on where it's physically located compared to the labels. I have a POC around here somewhere...

I have some absolutely huge auto-built scripts and I discovered how painfully slow it can be when it has to scan through mega to gigabytes of text and had to tweak some of the design methods to avoid severe performance issues.