Code Optimization

Interesting things in software development and code optimization

Visual Studio 2017 and Razor problem

Hello,


If you have the same problem as me then you see just black text when you open any cshtml file, something like that:

so, nothing highlighted, even css and pure html.


Also, in my case there were no "Add View..." on solution context menu and on controller cation context menu.


Unfortunately what did help me is complete uninstall of the VS 2017 and installing again.


hope it will help you as well.


Thank you



1vqHSTrq1GEoEF7QsL8dhmJfRMDVxhv2y



Drive C, Free space and Intel Driver Update Utility

Hello there,


Have not posted new articles for a long time and this is the next useful post about Drive C:, Free Space and Intel Driver Update Utility.


I was trying to free a little bit more space on my 128GB drive C: because of almost all space had been etan and 5GB left.

As always I started from the Windows folder and my impression was that it occupied 25GB from 128GB only!

Huh! Interesting. I had started digging dipper and found that ProgramData->Intel folder occupied 35GB!!! 

35GB!!! for what?


Actually I figured out that Intel Driver Update Utility stored some data files there with no really useful reason.


So the solution is to Uninstall this Intel Driver Update Utility and it automatically frees the space.

(or you can just delete the .etl files)


Here you are - free 35GB of space on drive C: :)


Not only Windows likes eating  ;)


Have a good day!


1vqHSTrq1GEoEF7QsL8dhmJfRMDVxhv2y



Javascript and jQuery - creating a lot of elements like a big grid


Hello dear friends,


Last time I did create a big grid using jQuery and Javascript, and faced with the performance problem.




My task was to create a big calendar grid that should have 20 rows at least and 180 columns (each column for each day for the 6 month period). While developing this grid I had noticed that Microsoft Edge and FireFox browsers hung during this creation cycle for a few seconds (Google Chrome seemed much better). My first method did create each cell for every column and row.

So how to optimize this? I did some googling and found a suggestion to use setTimeout function to avoid browser hanging, but it didn't help a lot in my case. Ugh! What should I do with it. Just in case, here is the piece of code I used to create my grid:

.....

var row, cell;

for(var r=0;r<20;r++)

{

    row = $("<div class='row'></div>");

    for(var i=0; i<180;i++)

    {

         cell = $("<div class='cell'></div>");

         ..........

        row.append(cell);

    }

    ....

    grid.append(row);

}


So, looks pretty simple? I was thinking for a few days on it trying to understand what could I do with it.

At some point I just had thought "what if create one row only and then just clone it as much as needed?". And yes, I was completely right! :) it did reduce time from 4-5 seconds to less than 1 second:

.....
var row, cell;


{
    row = $("<div class='row'></div>");

    for(var i=0; i<180;i++)
    {
         cell = $("<div class='cell'></div>");
         ..........
        row.append(cell);
    }
    ....
    grid.append(row);
}

for (var c = 1; c < 20; c++) {
   grid.append(row.clone(false).off());
}

So now its clear that the clone method grid.append(row.clone(false).off()); much much faster than creating a new elements.



Thank you and see you next time :)


1vqHSTrq1GEoEF7QsL8dhmJfRMDVxhv2y



MS SQL - Speed up Order By with OFFSET FETCH paging

UPDATE:

So adding nonclustered index, as the MS SQL Execution Plan suggests, seems reduced the query time even more, here is the suggested nonclustered index:

USE [myDB]

GO


CREATE NONCLUSTERED INDEX NONCLUSTERED_INDEX2_tblPictures

ON [dbo].[tblPictures] ([RatingTotal],[shape])

INCLUDE ([PictureID],[OwnerID],[PictureTypeID])

GO

but using only nonclustered index, without my #temp table technic, seems does not help too much.


Hello,

This time I'm going to share my solution on how I did reduce time of my SQL query with Order By clause by almost x2 times.

Firstly let me show my original query:

select @rowstotal = count(*)

From [dbo].[tblPictures]

where (@OwnerId = 0 OR @OwnerId = [OwnerID])

and (@FilterBy = 0 OR @FilterBy = PictureTypeID)

and (@Shape = '' OR @Shape = [shape])



Select

@rowstotal as TotalCount

, PictureID

, OwnerID

, PictureName

, [Description]

, Description2

, Description3

, aspectRatio

, [min]

, [max]

, [percent]

, thumbWidth

, thumbHeight

, processState

, keywords

From [dbo].[tblPictures]

where (@OwnerId = 0 OR @OwnerId = [OwnerID])

and (@FilterBy = 0 OR @FilterBy = PictureTypeID)

and (@Shape = '' OR @Shape = [shape])

Order By RatingTotal Desc

OFFSET @pageNumber ROWS FETCH NEXT @pageSize ROWS ONLY;


So to be able to calculate pages we have to know the total number of rows in the DB. Each row will contain TotalCount - total number of rows


(pay attention, that the techinc COUNT(*) OVER () as TotalCount is slower than just select @rowstotal = count(*) From that I use in my queries )


Then we select all needed columns with the order and paging technic.

Everything looks great, simple and fast unless you got more than 300 000 rows in the table.

Main problem here is that the Order By clause takes 98% of the whole stored procedure and in my case it takes 5 sec in total.

How to speed it up? 

I did google a lot of posts and almost everyone suggests to use indexes or nonclustered indexes, or other things.

As I'm not DBA and do not know a lot about all these things I decided to check what if I would select only one column instead of all of them? 

And when I got my 40 rows for one page I would select the rest of columns?

I did write some test query and had been surprised that it took almost x2 time less than before.


So here is the new query:

IF OBJECT_ID(N'tempdb..#tempPage', N'U') IS NOT NULL

DROP TABLE #tempPage;


create table #tempPage

(

TotalCount int null

, PictureID int

, OwnerID int null

, PictureName nvarchar(500) null

, [Description] nvarchar(500) null

, Description2 nvarchar(500) null

, Description3 nvarchar(max) null

, aspectRatio decimal(18,2) null

, [min] money null

, [max] money null

, [percent] decimal(18,2) null

, thumbWidth decimal(18,2) null

, thumbHeight decimal(18,2) null

, processState varchar(50) null

, keywords varchar(500) null

)


insert into #tempPage

Select

null --@rowstotal

,PictureID

,null

,null

,null

,null

,null

,null

,null

,null

,null

,null

,null

,null

,null

From [dbo].[tblPictures]

where (@OwnerId = 0 OR @OwnerId = [OwnerID])

and (@FilterBy = 0 OR @FilterBy = PictureTypeID)

and (@Shape = '' OR @Shape = [shape])

Order By RatingTotal Desc

OFFSET @pageNumber ROWS FETCH NEXT @pageSize ROWS ONLY


Update t

Set t.OwnerID = p.OwnerID

,t.TotalCount = @rowstotal

,t.PictureName=p.PictureName

,t.[Description]=p.[Description]

,t.Description2=p.Description2

,t.Description3=p.Description3

,t.aspectRatio=p.aspectRatio

,t.[min]=p.[min]

,t.[max]=p.[max]

,t.[percent]=p.percent

,t.thumbWidth=p.thumbWidth

,t.thumbHeight=p.thumbHeight

,t.processState=p.processState

,t.keywords=p.keywords

From #tempPage as t

INNER JOIN [dbo].[tblPictures] as p on p.PictureID = t.PictureID;

select * from #tempPage;

DROP TABLE #tempPage;


 Now we use a temp sql table to select only IDs firstly and then we update all 40 rows and set all other columns' values.

Also do not forget to drop temp table before and after to avoid existing table errors.


So this is the way that reduced my query time from 5 seconds to almost 2 seconds in total.


(SQL Server 2012 version: x64 11.0.3156.0)


Of course, if I would add nonclustered index, as MS SQL Graphical Execution Plan suggests, it may be even faster, but to be able to add them we have to understand what it is and how to use it. So maybe next step will be to learn and add nonclustered index ;)



Thank you and see you soon :)

 







1vqHSTrq1GEoEF7QsL8dhmJfRMDVxhv2y



Mouse pointer, audio and video lagging on ASUS R515M (X553MA)

Hello friends,


If you have the ASUS R515M (X553MA) notebook as me and you have mouse, audio and video lagging all the time, then you got to the right place and it is absolutely possible that it will help you.

What I have come up is the following - under the Device Manager you will find small thing named "HID-compliant wireless radio controls" device:




I don't know what is it for and have just DISABLED it. 

Reboot your notebook and after that everything should work well. In my case it has fixed mouse pointer lagging, audio lagging and video lagging.


Thank you :)




1vqHSTrq1GEoEF7QsL8dhmJfRMDVxhv2y



3T - Time Tracker for Trello

Hello friends,


If you use Trello as project management tool then you know how good it is and really simple and useful.

I use it as well and really appreciate it. I do like it because of it is really simple, clear and powerful at the same time.

As me, you just need some time tracking tool and reporting tool to be able to track everything and monitor workload in real time.

There is already such web application that I use and recommend it to you - this is the 3T - Trello Time Tracker 

It will show you currently in progress tasks, will track time spent for each task and provide you with excel reports.

Here is a quick guide on how to use it:


Step 1

Go to the 3T website and sign-up with your Trello account. 3T counts the time spent for any card in the Doing/Current/Working/Ongoing list for the developer/team-member that has dropped it onto the list. 

There is no difference who dragged out it.


Step 2

Authorize our application to let it be with your boards. Depending on the boards and organizations workload you have, it will be ready in a while.


Step 3

Track your boards and organizations automatically. 3T will synchronize all organizations and boards for you automatically.


Step 4

Just use Trello as usual – create boards, cards, and teams as you like, drag-and-drop lists when you need. 

The run-time for cards in your lists will be tracked by our app. The time will be tracked for board and list, and card, and for member who dragged and dropped the card into the Doing/Current/Working/Ongoing list.


Step 5

Head over to the Timesheet page to see your time sheets and generate excel reports for it.



Hope it will help you and provide everything you need to manage and track your projects.


Thank you and see you soon ;)



1vqHSTrq1GEoEF7QsL8dhmJfRMDVxhv2y



the debugger's worker process (msvsmon.exe) unexpectedly exited

Hello friends,


seems that you just have faced the same problem as me - "the debugger's worker process (msvsmon.exe) unexpectedly exited"


Quick and easy solution for that is just to DELETE all breakpoints:

- DEBUG -> Delete All Breakpoints


Thank you,

and see you son ;)


1vqHSTrq1GEoEF7QsL8dhmJfRMDVxhv2y



Ratee - rate through the World

Ratee - rate everything and everywhere


With the Ratee app you can rate everything and everywhere.

You like a pub - give it 5 starts and let other people and tourists know about it.

You do not like a pub or a service - give it minimal rate and share it with other people and tourists.



Facebook page

Windows phone 10



Android



Official page and download links


Feedbacks and ratings are welcome! :)


Thank you


1vqHSTrq1GEoEF7QsL8dhmJfRMDVxhv2y