Content Developer II at Microsoft, working remotely in PA, TechBash conference organizer, former Microsoft MVP, Husband, Dad and Geek.
122728 stories
·
29 followers

568. Children of Dune Miniseries Review (with Andrea Kail, Matthew Kressel, Rajan Khanna)

1 Share
Panel



Download audio: https://www.podtrac.com/pts/redirect.mp3/www.johnjosephadams.com/geeksguide/geeksguide568final.mp3
Read the whole story
alvinashcraft
14 minutes ago
reply
West Grove, PA
Share this story
Delete

Rider 2024.1: New Monitoring Tool Window, Collection Vizualizer, .NET Aspire, AI Assistant Plugin

1 Share

JetBrains has released Rider 2024.1. This release contains a new monitoring tool window and a collection visualizer. There also appeared the plugins: .Net Aspire, AI Assistant and features regarding debugging.

By Robert Krzaczyński
Read the whole story
alvinashcraft
14 minutes ago
reply
West Grove, PA
Share this story
Delete

The Art of SQL Server Tuning

1 Share

The customer faced challenges in managing their customers' calling activity data, which affected their billing and payment services. Due to the increasing volume of data, processing times exceeded 24 hours, causing a delay in real-time processing and resulting in reports reflecting data that was more than a day old. However, after implementing our advanced solution, the customer witnessed significant improvements in their financial transactional operations.
To address the issue, a meticulous analysis was conducted, and several strategic measures were implemented. Initially, the team tried to mitigate the problem by increasing CPU and memory allocation for each machine. Unfortunately, this solution proved ineffective as the issue resurfaced shortly afterward.

Subsequently, an opensource tool was installed on the SQL Server VM, allowing comprehensive metrics data to be gathered. After spending an additional four hours carefully examining the logs, a critical discovery was made. It was found that the statistics had a consistently low sample rate, consistently falling below 5%. To resolve this issue, the team recommended adjusting the sample rate parameter in the Update Statistics jobs and enabling PERSIST_SAMPLE_PERCENT to align with the maintenance job's sample rate. Additionally, they advised increasing the MAXDOP setting from 1 to 8.

When SQL Server creates or updates statistics and a sampling rate is not manually specified, the default sampling rate may not accurately represent the data distribution, leading to a degradation of query plan efficiency.

Let’s check stats on this table then. I’m searching for stats on table orders with column col2 (part of the join argument):
SELECT ss.stats_id, ss.name, filter_definition, last_updated, rows,
rows_sampled, steps, unfiltered_rows, modification_counter, persisted_sample_percent,
(rows_sampled * 100)/rows AS sample_percent
FROM sys.stats ss
INNER JOIN sys.stats_columns sc
ON ss.stats_id = sc.stats_id AND ss.object_id = sc.object_id
INNER JOIN sys.all_columns ac
ON ac.column_id = sc.column_id AND ac.object_id = sc.object_id
CROSS APPLY sys.dm_db_stats_properties(ss.object_id, ss.stats_id) shr
WHERE ss.[object_id] = OBJECT_ID('[Sales].[SalesOrderHeaderBulk]')
AND ac.name = 'OrderDate';
We see a statistic for the index used above, with a sampling rate of 6 percent. Let’s say I really need to improve estimations, and that having a higher sampling rate could just do that.

Yan_Liang_0-1716058951852.png

 

So I’ll just update this statistic, and while I could try to find a better (and higher) sampling rate, for this demo I’ll just update with full scan:
UPDATE STATISTICS [Sales].[SalesOrderHeaderBulk] [IX_OrderDate] WITH FULLSCAN

Yan_Liang_1-1716058951854.png

I really want to always update this statistic with 100 percent sampling rate, so I can now use the following PERSIST_SAMPLE_PERCENT keyword:
UPDATE STATISTICS [Sales].[SalesOrderHeaderBulk] [IX_OrderDate]
WITH FULLSCAN, PERSIST_SAMPLE_PERCENT = ON

The table name has been changed for demonstration purpose from customer’s database.


Upon implementing these recommendations, the customer successfully resolved the replication link issue, resulting in a remarkable improvement in the SQL Server's processing capacity.

Read the whole story
alvinashcraft
14 minutes ago
reply
West Grove, PA
Share this story
Delete

Reviewing Code With GPT-4o, OpenAI’s New ‘Omni’ LLM

1 Share
AI

This week OpenAI gave us access to GPT-4o (“o” for “omni”), which aims to compete better in speech recognition and conversation. It’s is almost certainly a stronger LLM, too. But can it do a code review? I put it through some tests to find out.

To start with, I checked if it could do long multiplication:

This is correct, as you can confirm on any online calculator. Note that it doesn’t attempt to “work through” the result for you — it has just passed it to a calculator. The “view analysis” icon at the end basically confirms this. Finally! This has failed to work on previous models.

I have no personal interest in formal code reviews. Yes, sometimes a junior developer might actually demand one, but unit tests and pairing sessions will usually suffice in sanding away bad code practice. But a few mumbled comments can help indicate mild unease with code, without appearing to be imposing some kind of authoritarian order over easily rewriteable snippets. In short, a code review is more of a social interaction than anything. Focus on engineering issues, not code semantic detailing.

However, code reviews are a good LLM use case for developers. Here I’ll look at three different bits of code, each of which simply draws a box with a diagonal line. I’ll add problems and see how GPT-4o (via ChatGPT) reviews them.

Here we start with our simple diagonal line routine in C#:

using System; 

public class Program 
{ 
  public static void Main() 
  { 
    BoxWithDiagonalLine(5); 
    BoxWithDiagonalLine(6,1); 
    BoxWithDiagonalLine(6,-1); 
    BoxWithDiagonalLine(2); 
    BoxWithDiagonalLine(-1); 
  } 

  // Example 1
  public static void BoxWithDiagonalLine(int boxsize, int linepos = 0) 
  { 
    for(int i=0; i < boxsize; i++) 
    { 
      for (int j = 0; j < boxsize; j++) 
      { 
        if (j == linepos) Console.Write("x "); 
        else Console.Write("o "); 
      } 
      linepos++; 
      Console.Write("n"); 
    } 
    Console.Write("n"); 
  } 
}


You can throw this into https://dotnetfiddle.net/ (set the compiler to .NET 6 at least, though) and see the responses:

This is fairly simple, and relatively self-explanatory. An outer loop controls the rows, an inner loop places the “x” in the right place. The variable naming is minimal, but the code is short. There is a default value for the method to give a full diagonal line from top left to bottom right. Whereas we can move the start line position left or right, it doesn’t make much sense to have a negative boxsize. So we could improve it by turning the method parameter to an unsigned int. This would immediately stop the last example from even compiling. A wildly large linepos will not be visible, but it isn’t dangerous.

So far, there is little to comment on.

In the second example, I will replace the for loops with while loops:

// Example 2 
public static void BoxWithDiagonalLine(int boxsize, int linepos = 0) 
{ 
  int i = 0; 
  while(i++ < boxsize) 
  { 
    int j = 0; 
    while (j++ < boxsize) 
    { 
      if (j == linepos + 1) Console.Write("x "); 
        else Console.Write("o "); 
    } linepos++; 
    Console.Write("n"); 
  } 
  Console.Write("n"); 
}


Now this works, but deserves a slight eyebrow raise. By post-incrementing the loop variables (the ++ after the i and j mean the values are read first before they are increased by one) we save some space, but we need that ungainly linepos + 1 expression. A while  doesn’t express the beginning and end state quite so nicely as a for loop does — but we are not sliding into any madness.

We make one last change. We now have a variation that does the wrong thing. It tries to use linepos to control the outer loop:

//Example 3 
public static void BoxWithDiagonalLine(int boxsize, int linepos = 0) 
{ 
  while(linepos < boxsize) 
  { 
    int j = 0; 
    while (j++ < boxsize) 
    { 
      if (j == linepos + 1) Console.Write("x "); 
        else Console.Write("o "); 
    } 
    linepos++; 
    Console.Write("n"); 
  } 
  Console.Write("n"); 
}


In an unnecessary attempt to remove one loop variable, the box itself will no longer be complete — although it will work with the default value. In fact, this solves a different problem, always reliably finishing with a cross in the bottom corner.

This poor code could probably come about because the developer continued to use a while inappropriately.

So let’s summarize the way we can look at the different versions:

  • The first example is fine, but we could force the parameter to be positive. Although, it is not crystal clear what the code does without comments.
  • The second uses a while loop, which doesn’t quite have the certainty of a for loop. It also makes for an ugly expression to take into account the post-increment.
  • The third example is plain wrong, even though it gets the result right in the default case

What do we expect from an AI code review? First of all, I have given it no comments, so will it work out what the code does? Only the name of the method reveals this.

Here is GPT-4o response:


“Your code is functional and effectively generates a box with diagonal lines based on the provided parameters. However, there are a few improvements and edge cases to consider:

  1. Input Validation: Ensure that the box size is positive and greater than 1, since a box with a size less than 2 doesn’t make much sense.
  2. Handling linepos: Improve handling of diagonal positions to ensure the diagonals are correctly drawn when linepos is negative or greater than the box size.
  3. Code Readability: Add comments and improve variable naming for better readability and maintenance.”

So it kind of did understand what the code did — even if it thought the program drew “lines” not a “line”. This is still very good.

The code it suggested was the following:

// ChatGPT4o suggested code 
public static void BoxWithDiagonalLine(int boxSize, int linePos = 0) 
{ 
  if (boxSize < 2) 
  { 
    Console.WriteLine("Box size must be greater than 1."); 
    return; 
  } 

  // Adjust linePos if it's out of the box boundaries 
  if (linePos < 0) linePos = 0; 
  if (linePos >= boxSize) linePos = boxSize - 1; 
  for (int i = 0; i < boxSize; i++) 
  { 
    for (int j = 0; j < boxSize; j++) 
    { 
      if (j == linePos) Console.Write("x "); 
        else Console.Write("o "); 
    } 
    linePos++; 

    // Reset linePos if it goes out of the box boundaries 
    if (linePos >= boxSize) linePos = 0; 
    Console.Write("n"); 
 } 
 Console.Write("n"); 
}


Here are the results of putting this into dotnetfiddle.net:

I think most people would be happy with the size less than two guards. It also camel-cased the params nicely, as this is right for C#. Unfortunately, it missed the idea of changing the position to allow for the line to start lower down. And by resetting the linepos, we get that unfortunate error at the bottom of the second example.

However, as code review, it hit the right note.

More Examples

Let’s feed it the second example and see how it does. Let me pick out the interesting comments:


“The use of while loops is functional but could be less intuitive compared to for loops for such iterations.”


Excellent. This is exactly the right note.


“The condition j == linepos + 1 is used to determine where to place “x”. This works but can be made more intuitive by aligning with the index i.”


Again, this is good. It understands the difference between functionality and readability.

The produced code clamped the value of linepos, and rather oddly used the modulo function to change the value. But it ended up with the same result. It reverted to for loops, which is excellent.

Finally, let’s deliver the bad Example 3, and see how it fairs. Oddly, it didn’t spot the bug, but did suggest the following:


“Edge Cases:

– When linepos is negative, it works but may not be intended.”


This is an indication that it didn’t quite understand the code — although, again, I never explicitly stated what I was doing. So perhaps a wrapping line may have been a reasonable guess?

Conclusion

Overall, I was quite impressed with the nature and the delivery of the review. The code GPT-4o produced was less promising, but it did ok. There was no “great clomping foot of nerdism” in the criticism of the code; instead, it gently nudged the reader in a better direction.

This is perhaps not where I expected to end up — with a good attitude but slightly inaccurate code. However, I would be happy to let this review be seen by a nervous junior; in that respect it does a slightly better job than some humans.

The post Reviewing Code With GPT-4o, OpenAI’s New ‘Omni’ LLM appeared first on The New Stack.

Read the whole story
alvinashcraft
3 hours ago
reply
West Grove, PA
Share this story
Delete

Rust <=> C++

1 Share
Mara Bos joins Phil and Timur. Mara talks to us about her work on the Rust evolution team and how she uses embedded Rust for drone flight controllers. We chat about some of the differences and similarities between C++ and Rust, and what the two languages can, and should, learn from each other.

News

Links





Download audio: https://traffic.libsyn.com/cppcast/CppCast-382.mp3
Read the whole story
alvinashcraft
3 hours ago
reply
West Grove, PA
Share this story
Delete

Build a Generative AI App in C# with Phi-3-mini LLM and ONNX

1 Share

Microsoft recently released the new Phi-3-mini SLM (small language model), and I previously wrote about running Phi3 locally using Ollama. I’ve been exploring the world of hosting AI models in code lately, and this stuff is getting really interested. It turns out that among the tools to run AI models locally, there are developer tools […]

The article Build a Generative AI App in C# with Phi-3-mini LLM and ONNX appeared first on Build5Nines.

Read the whole story
alvinashcraft
3 hours ago
reply
West Grove, PA
Share this story
Delete
Next Page of Stories