Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
brap
Aug 23, 2004

Grimey Drawer
I don’t understand. If your setup is properly signed why does AV care?

Adbot
ADBOT LOVES YOU

B-Nasty
May 25, 2005

LongSack posted:

Just starting, and haven’t gotten to that point yet. I’m very aware of Dapper (Tim Corey is a big fan), but I’m starting with the creation of the database and tables from the entity classes, which I don’t think Dapper handles. Dapper is definitely on my radar though.

What is the real value of that?

Often, relational data isn't stored in a really simple class=table format, and then, as time goes on, you're trying to tweak the class change->migration script logic in whatever strange tool you use. It's not like creating a table in a SQL script is difficult, and handwritten migrations will never surprise you or destroy data in a way you didn't expect.

I've never used something like EF and not been sorry I did a few months later. Your database schema and the data it contains is far more valuable than your C# code.

distortion park
Apr 25, 2011


B-Nasty posted:

What is the real value of that?

Often, relational data isn't stored in a really simple class=table format, and then, as time goes on, you're trying to tweak the class change->migration script logic in whatever strange tool you use. It's not like creating a table in a SQL script is difficult, and handwritten migrations will never surprise you or destroy data in a way you didn't expect.

I've never used something like EF and not been sorry I did a few months later. Your database schema and the data it contains is far more valuable than your C# code.

I feel the same way. Generating classes that represent row objects (or query output rows etc.) otoh is extremely nice (and works great with stuff like Dapper!) There are a bunch that do it as a tooling step (typescript has some particularly nice ones), but f# can do it live!

beuges
Jul 4, 2005
fluffy bunny butterfly broomstick
I use EF a lot, and I’ve never done code-first, even though I am typically also doing the db design as well as building the code. It makes more sense to me to build the db in the db, review a database diagram to make sure all the relationships and stuff are right, and then have EF scaffold the db into entity classes.

beuges
Jul 4, 2005
fluffy bunny butterfly broomstick
Is there a way in Visual Studio (2022 if it matters) to hard limit the memory available to a process being debugged so I can try and track down what’s causing OutOfMemory exceptions?

Kyte
Nov 19, 2013

Never quacked for this
You don't need to do that

fuf
Sep 12, 2004

haha
I'm having another stab at implementing some logging for my practice Blazor Server app

I'm looking at stuff like Serilog and it looks cool, but the thing is I want to output the log to the UI rather than a file, console, or external sink, and I can't really find anything about that.

Would it be possible to setup Serilog (or some other logging package) with a Blazor component so that the component displays the log? How do I access the log from the component? Or the other way around: how do I tell the log to send its log events to the component?

mystes
May 31, 2006

fuf posted:

I'm having another stab at implementing some logging for my practice Blazor Server app

I'm looking at stuff like Serilog and it looks cool, but the thing is I want to output the log to the UI rather than a file, console, or external sink, and I can't really find anything about that.

Would it be possible to setup Serilog (or some other logging package) with a Blazor component so that the component displays the log? How do I access the log from the component? Or the other way around: how do I tell the log to send its log events to the component?
Normally you would log it to an actual sink and then if you want to display it in some sort of dashboard you would display it the same way you would display data from any database or whatever?

If you're just trying to do some sort of output within a single user session then maybe serilog isn't what you want.

fuf
Sep 12, 2004

haha

mystes posted:

If you're just trying to do some sort of output within a single user session

yeah exactly this

I guess I thought maaaybe it might be good to also write to a file but no it's mostly just info for the user within a single session

ok so I should probably just come up with my own little logging service

Just-In-Timeberlake
Aug 18, 2003

fuf posted:

ok so I should probably just come up with my own little logging service

lol no, don't try to reinvent the wheel, I guarantee what you want exists already.

Here, check this out using Serilog:

https://stackoverflow.com/questions/35567814/is-it-possible-to-display-serilog-log-in-the-programs-gui

fuf
Sep 12, 2004

haha

Thank you. I did actually see that but glossed over it because it looked like they were talking about desktop apps.

But I added a new sink like in the suggestion and we are in business my friends

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
Is there a way to adjust exponent formatting in a ToString() call without having to muck with a string each time?

Like, let's say I have some float-point type and I'm printing it with ToString("e8"). But I may be adjusting that 8 quiet often. It feels silly to do that as a string operation. There's a NumberFormatInfo that has some stuff that should help but I don't see how I can get it to print an exponent. NumberFormatInfo carries settings for all the different types so just setting the number of decimal digits doesn't seem enough. Is it something like ToString("e", numberFormat) or something?

aperfectcirclefan
Nov 21, 2021

by Hand Knit
You can use a placeholder

ToString($"e{numberFormat}")

I believe

insta
Jan 28, 2009

aperfectcirclefan posted:

You can use a placeholder

ToString($"e{numberFormat}")

I believe

invoking the entirety of string interpolation to build a 2 character string? jfc

aperfectcirclefan
Nov 21, 2021

by Hand Knit

insta posted:

invoking the entirety of string interpolation to build a 2 character string? jfc

What would you recommend then?

insta
Jan 28, 2009

aperfectcirclefan posted:

What would you recommend then?

I wanted to say something with NumberFormatInfo, but at a minimum just a string.Concat will be a lot faster than interpolation (which ultimately ends up using concat deep in the bowels after doing a bunch of character-by-character analysis and state machine tracking for finding curly braces).

code:
    [MemoryDiagnoser]
    public class StringFormatTest
    {
        private readonly int Digits = 8;

        [Benchmark]
        public string Concatted() => string.Concat("e", Digits);

        [Benchmark]
        public string Interpolated() => $"e{Digits}";
    }

|       Method |     Mean |    Error |   StdDev |  Gen 0 | Allocated |
|------------- |---------:|---------:|---------:|-------:|----------:|
|    Concatted | 27.05 ns | 0.596 ns | 0.686 ns | 0.0134 |      56 B |
| Interpolated | 54.88 ns | 1.171 ns | 1.253 ns | 0.0134 |      56 B |
I don't know what the impact is as you make the string bigger, and I guess for 2 characters it doesn't really add that much (although IMO they're equally as readable) here. It's still twice as fast to concat, but it's nanoseconds.

insta fucked around with this message at 22:48 on Feb 27, 2022

SirViver
Oct 22, 2008
Like, if you really, really think the string concatenation is a performance problem in your usage scenario (it most likely isn't), you could cook up something like this:
C# code:
public static class NumberFormats
{
    public static string[] E { get; } = Enumerable.Range(0, 28).Select(i => "E" + i).ToArray();
}

...
num.ToString(NumberFormats.E[8]);
String interpolation isn't a good idea if the whole issue was performance, as it has most likely worse performance or at best equal performance to string concatenation.

If you write $"E{numberFormat}" (assuming numberFormat is an int) then that compiles to string.Format("{0}", numberFormat), which isn't a good idea considering all the performance overhead of that. You can trick it with $"E{numberFormat.ToString()}" that would compile to string.Concat("E", numberFormat.ToString()), but at that point just writing "E" + numberFormat is better in every way.

SirViver fucked around with this message at 22:44 on Feb 27, 2022

mystes
May 31, 2006

I feel like it's not going to be worth worrying about the performance of something like this in most cases...

mystes fucked around with this message at 22:48 on Feb 27, 2022

aperfectcirclefan
Nov 21, 2021

by Hand Knit
I had no idea there was that big of a performance hit with interpolation.

mystes
May 31, 2006

aperfectcirclefan posted:

I had no idea there was that big of a performance hit with interpolation.
I don't think there's actually a hit with interpolation since the actual interpolation is compiled out, but I think SirViver is just saying that since if you're doing number formatting that part will compile to String.Format (and then that will be concatenated), there's overhead from the string.format call or something like that?

mystes fucked around with this message at 22:51 on Feb 27, 2022

insta
Jan 28, 2009

aperfectcirclefan posted:

I had no idea there was that big of a performance hit with interpolation.

I suspect I'm equating string.Format runtime performance with interpolation, which may be broken down into string.Concat / StringBuilder.Append by the compiler to begin with.

aperfectcirclefan
Nov 21, 2021

by Hand Knit
That makes sense then gotcha. Im just starting getting deeper into C# so good to know this stuff!

That said, do any of you have a recommendation for a C# book that is more referential than tutorial?

B-Nasty
May 25, 2005

mystes posted:

I feel like it's not going to be worth worrying about the performance of something like this in most cases...

What!? Burning developer hours (at a cost of thousands of dollars) to determine the most performant way to format a string is the best use of resources.

Unless this is some crazy hot-path, almost anything else you could be working on would bring more value to the business than saving 5 nanoseconds worth of processing time.

insta
Jan 28, 2009

B-Nasty posted:

What!? Burning developer hours (at a cost of thousands of dollars) to determine the most performant way to format a string is the best use of resources.

Unless this is some crazy hot-path, almost anything else you could be working on would bring more value to the business than saving 5 nanoseconds worth of processing time.

Having knowledge ahead of time that string.Concat is faster than Interpolation (and both are WAY faster than string.Format) can prevent you from writing slower code from the outset though. Hot paths should be tested for, yes, but we also start out with tested-faster code.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!

mystes posted:

I feel like it's not going to be worth worrying about the performance of something like this in most cases...

You're right but it doesn't stop me from feeling stupid about concatenating a character to an integer converted into a string, only to have it parse the string under the hood and extract out the operations I really want to do. I was hoping I could skip the middle man and the resulting code could be more clear.

brap
Aug 23, 2004

Grimey Drawer
The platform has made improvements to string interpolation which will eventually make it as good as concatenation or better in many cases.

https://devblogs.microsoft.com/dotnet/string-interpolation-in-c-10-and-net-6/

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

brap posted:

The platform has made improvements to string interpolation which will eventually make it as good as concatenation or better in many cases.

https://devblogs.microsoft.com/dotnet/string-interpolation-in-c-10-and-net-6/

And even if they hadn't, worrying about the performance characteristics of one vs the other is a pointless micro-optimization that has a vanishingly small likelihood of ever being the culprit of a performance issue.

insta
Jan 28, 2009

New Yorp New Yorp posted:

And even if they hadn't, worrying about the performance characteristics of one vs the other is a pointless micro-optimization that has a vanishingly small likelihood of ever being the culprit of a performance issue.

Yes, string concatenation, never known to be the source of performance problems.

Maybe it's different in your C# code, but in the code I inherit, string building is easily the #1 or #2 source of CPU-bound performance issues. The other is List<T>.Contains when HashSet<T>.Contains is equally viable.

Kyte
Nov 19, 2013

Never quacked for this
Just upgrade to .NET 6 :v:

brap
Aug 23, 2004

Grimey Drawer

New Yorp New Yorp posted:

And even if they hadn't, worrying about the performance characteristics of one vs the other is a pointless micro-optimization that has a vanishingly small likelihood of ever being the culprit of a performance issue.

I guess so. I follow two maxims regarding this:

1. Make it correct, then make it fast.
2. The profiler knows, you don’t.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

brap posted:

I guess so. I follow two maxims regarding this:

1. Make it correct, then make it fast.
2. The profiler knows, you don’t.

Exactly. I'm not going to agonize over the performance characteristics of the 90 different ways to build and format strings unless I discover it's a performance issue. I've worked on a lot of applications over the years and I've never seen one where performance wasn't IO bound, memory bound, or CPU bound somewhere much deeper in the bowels of the app.

brap
Aug 23, 2004

Grimey Drawer
I have worked on apps where string.Trim was the top line of the trace. Doing stuff like ‘s.Trim() == “some constant”’.

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

New Yorp New Yorp posted:

Exactly. I'm not going to agonize over the performance characteristics of the 90 different ways to build and format strings unless I discover it's a performance issue. I've worked on a lot of applications over the years and I've never seen one where performance wasn't IO bound, memory bound, or CPU bound somewhere much deeper in the bowels of the app.

i've had string concatenated related performance issues cause noticeable performance impact, but it's usually something that would be in UI rather than backend - like if you have a feature that draws text in relation to something like mouse input (think like a photoshop style image editor with a text overlay), then slow string operations can make a difference in framerate of the resulting operation.

just write the code the easy way and profile it after you're done.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Bruegels Fuckbooks posted:

just write the code the easy way and profile it after you're done.

worms butthole guy
Jan 29, 2021

by Fluffdaddy
Is there a way to access the value in a SortedList and then iterate on that value? So i'd like to do (pseudo code):

code:
	CansOfDogFoodtoFeed = new SortedList<string, int>(){
			{"Buttercup", 1},
			{"Fido", 5},
			{"Kennedy", 2}
		}

	// This is what i'm not sure the right way to do
	foreach(dog in CansOfDogFoodtoFeed){
				dog.value++;
		}
So that effectively Buttercup has 2 cans now to eat.

Thanks!

Kyte
Nov 19, 2013

Never quacked for this

worms butthole guy posted:

Is there a way to access the value in a SortedList and then iterate on that value? So i'd like to do (pseudo code):

code:
	CansOfDogFoodtoFeed = new SortedList<string, int>(){
			{"Buttercup", 1},
			{"Fido", 5},
			{"Kennedy", 2}
		}

	// This is what i'm not sure the right way to do
	foreach(dog in CansOfDogFoodtoFeed){
				dog.value++;
		}
So that effectively Buttercup has 2 cans now to eat.

Thanks!

SortedList.Values doesn't work for you?

worms butthole guy
Jan 29, 2021

by Fluffdaddy

Kyte posted:

SortedList.Values doesn't work for you?

Didn't know about that, thank you!

raminasi
Jan 25, 2005

a last drink with no ice
I've seen bad string management take down a production web server. To be fair, the code was pathological, roughly this:
C# code:
string a = "First part";
a += "second part";
a += "third part" + "fourth part";
a += "fifth part" + "sixth part" + "seventh part";
// continue for like twenty lines
with most of those individual parts variables or function calls or what have you.

But then again, nothing is pathological until it is. I sure wish that whoever wrote that originally had cared about performance.

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

raminasi posted:

I've seen bad string management take down a production web server. To be fair, the code was pathological, roughly this:
C# code:
string a = "First part";
a += "second part";
a += "third part" + "fourth part";
a += "fifth part" + "sixth part" + "seventh part";
// continue for like twenty lines
with most of those individual parts variables or function calls or what have you.

But then again, nothing is pathological until it is. I sure wish that whoever wrote that originally had cared about performance.

Almost every time I've run into something like that, the problem was a hat on an even stupider problem e.g. imbeciles concatenating strings to make xml/json/html.

Adbot
ADBOT LOVES YOU

insta
Jan 28, 2009
I'm sorry I started the holy war on string performance. It's definitely bike-shedding. At the same time, if you never care because you've never needed to, it's easy to write concatenation code like that instead of the sightly clunkier StringBuilder version. If you know ahead of time what is and isn't fast, and they all look about the same, why wait until it's slow to write the other version?

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply