r/SoftwareEngineering • • Mar 28 '25
How big should a PR be?
I work in embedded and my team prefers small PRs. I am struggling with the "small PR" thing when it comes to new features.
A full device feature is likely to be 500-1000 lines depending on what it does. I recognize this is a "big" PR and it might be difficult to review. I don't want to make PRs difficult to review for my team, but I am also not sure how I should otherwise be shipping these.
Say I have a project that has a routing component, a new module that handles the logic for the feature, unit tests, and a clean up feature. If I ship those individually, they will break in the firmware looking for pieces that do not yet exist.
So maybe this is too granular of a question and it doesn't seem to bother my team that I'll disappear for a few weeks while working on these features and then come back with a massive PR - but I do know in the wider community this seems to be considered unideal.
So how would I otherwise break such a project up?
Edit: For additional context, I do try to keep my commit history orderly and tidy on my own branch. If I add something for routing, that gets its' own commit, the new module get its' own commit, unit tests for associated modules, etc etc
Edit 2: Thank you everyone who replied. I talked to my manager and team about this and I am going to meet with someone next week to break the PR into smaller ones and make a goal to break them up in the future instead of doing one giant PR.
16
u/telewebb Mar 28 '25
If it's mine, as big as I feel like it. If it's someone else's? No more than 10 lines and they should all be deletions.
4
u/[deleted] Mar 28 '25
3 YoE, have only seen PRs of full features(Ticket) yet. In scrum poker, if you estimete a high number you need to split the ticket up. This makes it a team descision how big the PR should be as you agreed the story points. You could work with feature toggles but i feel like this just adds complexity and you'd have to look into related PRs regarding this feature anyway.
You can always bring it up in daily tho if you think the leap of faith gets too big and you see a good split line.
4
u/RangePsychological41 Mar 28 '25
I’m as anti “agile” as it gets with the modern nonsense.
But “people over processes” solves half of the issues. Talk to your team. You sound like a great engineer to work with.
3
u/danielt1263 Mar 29 '25
I'm going to assume that as you develop, you are constantly running the app, or at least the test harness to make sure everything works as expected. Further, I will assume that these runs succeed at least some of the time, probably most of the time.
This means that you should be able to make several PRs per day, you've added a test or tests and all the tests pass. You commit your code to your local branch... You can make a PR at that point.
You have paused, because you have completed some sub-part of the ticket and your working out what to do next... I expect this happens to you at least a few times a day. You can make a PR at that point.
I personally think you should make at least one PR per day.
2
u/Fuehnix Mar 28 '25
Take my advice with a grain of salt, because I haven't worked on large dev teams before, but personally, I do commits everytime I have something worth writing a commit about/as often as I remember to.
So usually 1-3 subtasks committed at a time.
As far as PR go... Do it when you've finished a whole task and need to sync up with the other team members?
That's how I sync my backend with the frontend team at least.
2
u/[deleted] Mar 28 '25
Two words. Feature branch. Another two words, dependency injection. Both can help keep your PRs small. I’m a software engineer for more than a decade at a reputable company, 1000 lines in a PR is never acceptable.
2
u/mrdirtyminder Mar 28 '25
Going on 12 years, 15 if you count years in uni grinding for “experience”. It didn’t click for me until about 6 years ago. But now my commits are usually very small.
Using your example, I would first do PRs for the internal logic, each thing in its own PR with its own tests. Then I would add the routing and whatever needs to use this logic.
Ofc I sometimes need to build something from start to finish in a feature branch. Then I demo it to stakeholders, and if everything is cool I start extracting small PRs until I get everything in.
As with everything in life, take it with a grain of salt. Nothing is ever black or white. Some PRs need to be larger. Also, you’re different than me, and you work on different things and with different teams.
2
u/Angalourne Mar 28 '25
Disclaimer: I don't have embedded experience and it's very possible that the constraints involved would require a different PR strategy than what is typical.
Simply put, large PRs introduce risk. First, engineers are more prone to miss important issues the larger a PR is due to increased cognitive load and plain old laziness. This risks increased defects and technical debt. Second, large PRs take more time to review and make their way into the main development branch. This risks holding up other work items that may depend on that code. In small teams this is less problematic, but in larger teams this will grind everything to a halt very quickly. This in turn risks increased cost (both development cost and opportunity cost due to delayed releases).
You mentioned the PR being for a feature. Unless this is distinctive to embedded development due to unique constraints, that's a red flag for me. PRs should be reduced to minimal increments of functionality (in Microsoft DevOps it's the PBI) that doesn't break the build. A Feature would contain multiple PBIs that together deliver the feature's full functionality. The key is that each incremental functional PR does not leave the main development branch in a broken state (i.e. doesn't break the build). The degree of what "minimal" means will be determined by the team depending on the project and business.
11
u/Abject-Kitchen3198 Mar 28 '25
A lot of general advice does not apply to a lot of situations. Small PRs are nice to have but not always applicable. Having well structured and minimal code, doc and test package for the minimal increment that makes sense for a given feature could be a goal. Actual size may vary largely between PRs.
4
u/pyhacker0 Mar 28 '25
You can use feature branches to create many small PRs for a large feature. This does add maintenance work of keeping the feature branch in sync
1
u/Forward-Subject-6437 Mar 28 '25
The module and the cleanup feature should both be able to be delivered independently. Unit tests should be isolated and therefore deliverable on their own. Finish up with the consumer of the module -- your routing component.
4
u/Capable_Insurance_70 Mar 28 '25 edited Mar 28 '25
There multiple branching strategies to handle such cases, simpler might be to have long living feature branch for one epic and merge your PRS there
After everything is done and reviewed iteratively, you can create last PR targeting main, and functionally feature can be tested there, but all code should be already lgtm'ed by your colleagues in previous PRs
But most importantly it's all need to be agreed and discussed to use by whole team beforehand. Like for me it would not be an issue if you communicated at some point that we should expect unsplitable 1k lines PR, but maybe 2k is too extreme and we better split work in chunks for both of us
2
u/Recent_Science4709 Mar 28 '25
This is process smoke. If your PRs are too big, your tasks are scoped too wide, if your tasks are scoped correctly, your developers can’t stay in scope.
If everything is in scope and people are complaining about the size of the PR they are just whiners.
2
u/sitsatcooltable Mar 28 '25
lgtm
2
u/[deleted] Apr 04 '25
It depends, but for me ideal size is which takes around one hour to review or less.
2
u/AdeptLilPotato Mar 28 '25
The largest PR’s in normal work tend to be 300 ish lines. Sometimes it is bigger due to automated testing.
The goal is to keep it around this.
In your example, I’d start with a FF, because new features should typically be behind a FF.
So the first PR would be creating the FF. You also create a FF removal ticket and place it into the future when the FF should already be live to ensure it is cleaned up.
The second PR can be a skeleton. It might be adding the route and base skeletal structures of the new files that’ll be interacting with each other. No logic!! Make the logic easy for your team to review by having that in the following PR.
The third PR can either be the main logic for everything, and automated testing, or it can be the main logic for one piece at a time with automated testing. Depends on the complexity and how much is going on. If it would be a large PR in the first option, you could consider spreading it into multiple smaller PR’s. You said you struggle with that because one “piece” at a time would be looking for your other logic that doesn’t exist yet. I think you could make mock/placeholder data if needed, or start with the level that doesn’t call anything first. It is possible you need to think of it backwards compared to the plan you had. As in, build the piece that is called first, and doesn’t call anything itself. Then, you won’t run into a situation where your other file cannot “find” it.
As the person developing this, it is obviously not IDEAL to separate it into separate PR’s, it puts you behind the gate of how long it takes your team to review your work, and what if you branch off of it to continue, but then there’s some major changes due to review comments? Who knows. I know it isn’t the ideal situation, FOR YOU, however, it improves team cohesiveness. The goal is for you to make your PR small enough that you get deeper reviews and more feedback, and not only that, but also more ownership & understanding of the code. Ensuring there isn’t a knowledge silo. One of our principle engineers has said this a few times: “When you’re reviewing code, your approval means that you also have ownership of this code, and that if the code were to break, or a bug were to be found, you also have ownership to fix it, because you let the code into the code base”. He said that this is something to strive for, because it improves your ability to review other’s code, and it improves the solidity of code you allow into your code base.
2
u/elch78 Mar 28 '25
Zero. Trunk based ftw. PRs are for low trust environments.
1
u/sobrounabocha Mar 28 '25
RemindMe! 1 day
1
u/a_of_x Mar 28 '25
In my corner of existence, anything over 30 lines and or 3/4 files is questionable.
1
u/Successful_Creme1823 Mar 30 '25
Just make prs that you’d want to review.
1
u/shozzlez Mar 30 '25
If it’s big I usually do a code walkthrough after standup. I don’t expect someone to go through thousands of lines of code without context.
Also large PRs generally don’t get reviewed for quality as well. You may or may not care about that.
1
u/Dull-Structure-8634 Mar 30 '25
I personally try to keep my PR under 500 lines MAX. Normally I average about 150-200 lines.
This helps catch code smells and issues and my PR are reviewed in less than 2-3 hours.
By this time I have already started onto the next bit of my feature and just keep in sync with the changes of any.
If I have a very big PR (> 500 lines) I just mention why in the PR description (ex.: lots of unit tests or this part of the feature could not be split into smaller bits). Normally, there is no pushback when I do so.
1
u/[deleted] Mar 31 '25
This is a great resource for making your work packages smaller. Enjoy!
https://www.humanizingwork.com/the-humanizing-work-guide-to-splitting-user-stories/
1
u/Regular_Airport_7869 Apr 24 '25
Hey, that's a great question and IMO a topic, that can have a lot of impact on the development speed of a team.
First of all, I have not worked in your domain yet, so the approach I, we prefer might not work for you. Still sharing it. This is what I learned from working in ~ 10 teams:
So, there a bunch of problems with large PRs:
- as reviewer, you tend to look not closely and might miss important stuff like potential bugs more easily -> quality suffers
- it takes long to develop, so you get feedback late, which might result in going the wrong way for too long -> wasting time
- as reviewer, you probably avoid taking on such big code reviews, because they are not fun and do not give you a feeling of making good progress
- big PRs are more risky to cause problems and harder to debug after deploying to production
That being said, why do people still build big PRs (including me some time ago):
- you did not split a topic into small chunks
- you think, you can only create a PR when a big feature is completely finished
- when you put something to review, it always takes a long time until it's reviewed, so you want to have this wait time only once instead of for many PRs
- having small changes merged does not work well with your deployment process
We are working on a SaaS product in the real estate market in germany. In our current process (that I like a lot), we do the following:
Splitting into small chunks:
We split work into small chunks, that can be developed within one day max. Sometimes, we add changes, that is not used yet in production, but already have it added and tested via automated tests. Some refactorings are done as separate PRs also. In most cases, it should work to split into small chunks.
Different commits for different kinds of changes:
Every commit should focus on one thing. E.g. I split refactorings from new features in code. Sometimes, even a single rename is one commit. That allows a reviewer to review commit by commit and very quickly understand what has been done. The commit message is also very helpful here.
Quick reviews:
We made a habit of reviewing new code very quickly. A PR is usually reviewed within hours. This includes the time until someone starts and the time he or she finishes the review. This is only possible due to the small PRs. After every task, that one of us finished, we check for reviews again. That's another reason for the speed.
Seamless deployment process:
Finally, the deployment must be smooth. If the work after each merge is a lot, there is less motivation to have small PRs. Therefore, we try to automate as much as possible, so that on merge, there is basically no work left for the change to be deployed to production. If a feature is not finished yet, but started, we use a feature flag to disable it. Sometimes hardcoded. Sometimes, via a configuration concept.
This was a long story. I hope, this is helpful to you or someone else :)
1
u/Momus_The_Engineer May 08 '25
You sir are a good engineer that works with brainwashed idiots.
Breaking up PR’s to “keep them small” just obscures the true size and complexity.
Considering part of a change without considering the others is how defects sneak in.
I’m sorry they are misleading you. We need good engineers like you to fight the rampant mediocrity that permeates a once prestigious industry.
1
u/HKSpadez Jun 01 '25
Imagine if a coworker put up your PR. Would it be TLDR for you? If so, it's too long
1
u/potatopotato236 Mar 28 '25 edited Mar 28 '25
Seems more like a ticketing issue. Each PR should correspond to a maximum of one ticket. Each ticket should be a week's worth of work as the absolute max, but ideally closer to 2-4 hours worth. Tickets longer than 16 hour’s worth should nearly never be required. I don’t even remember the last time I worked on one of those.
Waiting several weeks to get feedback for a feature is a recipe for disaster.
1
u/agrrrcode Mar 29 '25 edited Mar 29 '25
Alright, that sounds great! Breaking a large PR into smaller ones is definitely the way to go. It’s an ambitious goal to balance modular development without breaking the firmware, but with the right branching strategy, you don’t have to resort to downsizing important features just to keep PRs small.
One way to turn around this issue is by creating a feature branch and branching off smaller branches and PRs from it. The thing is, when the feature branch gets enough code to be integrated into the firmware, we can merge it into the main or dev branch and build it without worrying about breaking. This way, you can adapt yourself to a workflow where code is reviewed in digestible pieces while still keeping everything functional.
Also, big PRs can make it harder for teammates who have their fingers in the pie—they might struggle to review or test everything at once. And if something goes wrong, it’s easier to pinpoint where a misstep happened in a smaller PR.
Sounds like you nailed it by discussing this with your team! Once you get the hang of structured PRs, your workflow will hit a stunning top speed without sacrificing code quality or best practices.