Hey guys! It has been a while! I hope everyone’s well & staying safe!
As things have slowed down a little with work, I thought I’d take the time to ask a couple of questions around the .NET ecosystem & I was hoping that some of you more experienced .NET dudes would be able to point me in some decent directions.
So, without further ado, I’m currently working on a project that’s really interesting, but the tech isn’t aging so well, some parts of the application simply haven’t been maintained & there are parts that have simply been abused by past developers.
I’m doing my best to manage the balance of trying to build new features while maintaining old ones, e.g. this morning I managed to reduce the time it takes for one endpoint to go from 16+ seconds down to a mere ~300ms. If I had the time, I’d try to decrease the time taken even further!
To cut through the baffling, I’ve started to implement cleaner coding practices to try & make the team follow, making life a lot easier for ourselves in terms of maintainability, extendibility, you name it.
Example Time
So in some API endpoint, I have the following code, it’s nothing too complicated & the complicated bits are all buried with some relatively simple layers of abstraction:
// Some other stuff... Auth, etc.
var docs = repo.GetDocuments().Select(g => g.ToJson()).ToList();
var states = repo.GetStates()
.Select(s => new PipelineStateViewModel {
Id = s.Id,
Colour = s.Colour,
Name = s.Name,
Order = s.Order,
Documents = PipelineStateViewModel.MapState(s.Id, docs),
Page = PipelineStateViewModel.GetPage(s.Id, docs),
PageSize = PipelineStateViewModel.GetPageSize(s.Id, docs),
Count = PipelineStateViewModel.GetCount(s.Id, docs)
}).OrderBy(s => s.Order)
.ToList();
var abandonedDocs = repo.GetAbandonedDocuments()
.Select(d => Mapper.Map(d, new DocumentListViewModel()))
.ToList();
var pipeline = new PipelineViewModel()
.MapFrom(repo.GetDocumentType())
.WithStates(states)
.WithAbandonedTypes(abandonedDocs);
// Some other code again...
But what shocked me is how before I included .ToList
, the performance of this endpoint was shocking, even though I used a Stopwatch
to quickly measure the performance. What confused the hell outta me is how on the backend it was taking around 800ms, not great, but I can live with it for the time being. But in the browser, it would take like 3s.
Since adding in .ToList
, it managed to cut the time taken to respond to 1.4s. I’ve been trying to do some homework on this & from what I’ve read online, if anything, adding a call to .ToList
should’ve theoretically slowed it down a little.
This goes to show that even after a year, there’s still one hell of a lot about the .NET ecosystem that really baffles me. I’m really trying to learn to love it, I really am giving it the benefit of the doubt, I approached the ecosystem with a lot of hesitation & reservations. Unfortunately, I’ve not had a great time with it!
In all fairness to the .NET ecosystem, this is more likely due to the fact that I’m working with a LOT of spaghetti code, I mean this is enough spaghetti to put you off pasta for life. It’s slowly getting better, don’t get me wrong, but as a team, we still have one hell of a way to go! We’ve had all sorts of issues, one of the more nightmare mode ones being how we’ve got a memory leak deep within & it’s more due to time, budget & resource that we simply haven’t been able to fix it quite yet.
But there have been issues that we’ve been having that just simply shouldn’t be issues, something as simple as routing. For the love of money, I cannot workout why sometimes some strings for some routes cause the entire thing to just catch fire & an entire controller instantly becomes inaccessible. Change it to something stupid & blam, it works. It’s not even like there’s another route that could conflict or anything like that, a part of my suspicion here is that there’s some config buried somewhere & I know we’re using some pretty dated dependencies also.
But that’s enough of my complaining about .NET, clearly a lot of developers love it, looking at questionnaires & whatnot. So I was hoping some wizard could point me down the path of enlightenment?