2

I have created f# solution and added one class library. Only one project in the solution and 5 files and 20 lines of code in each file. Still it will take more 2 minutes to build each time.

I have tried to clean solution. Also created new solution and project and includes same files, still it will take same time to build it.

Note : First I have created it as a Console Application then convert it into the Class Library.

Edit: Code Sample `

open System open Configuration open DBUtil open Definitions

module DBAccess =

let GetSeq (sql: string) =
      let db = dbSchema.GetDataContext(connectionString)  
      db.DataContext.CommandTimeout <- 0                        
      (db.DataContext.ExecuteQuery(sql,""))


let GetEmployeeByID (id: EMP_PersonalEmpID) = 
    GetSeq (String.Format("EXEC [EMP_GetEntityById] {0}",id.EmployeeID)) |> Seq.toList<EMP_PersonalOutput>

let GetEmployeeListByIDs (id : Emp_PersonalInput) = 
    GetSeq (String.Format("EXEC [EMP_GetEntityById] {0}",id.EmployeeID)) |> Seq.toList<EMP_PersonalOutput>`

configuration code snippets : `open Microsoft.FSharp.Data.TypeProviders

module Configuration = let connectionString = System.Configuration.ConfigurationManager.ConnectionStrings.["EmpPersonal"].ConnectionString

//for database,then stored procedure, the getting the context,then taking the employee table
type dbSchema =  SqlDataConnection<"", "EmpPersonal">
//let db = dbSchema.GetDataContext(connectionString)

type tbEmpPersonal = dbSchema.ServiceTypes.EMP_Personal`
Ravindra Sinare
  • 675
  • 1
  • 9
  • 25
  • MAY be You can tell Visual Studio not to load Symbols. you can edit it on Tools >> Options >. Debugging >> Symbols: – 10K35H 5H4KY4 Sep 24 '15 at 07:30
  • Microsoft Symbol Server is unchecked already. I have check the radio button to load only specified modules Still it will take 2 minutes to build. – Ravindra Sinare Sep 24 '15 at 07:48
  • Your description seems to be insufficient for reproducing the problem. First off, try to minimize the solution by removing other projects. Then run the build manually and see what steps take long time. It can be literally anything — resources on network drives, caching with type providers, and so forth. – Be Brave Be Like Ukraine Sep 24 '15 at 08:17
  • Hi bytebuster, I have only one project in this solution. – Ravindra Sinare Sep 24 '15 at 09:13
  • If there are only 100 lines total, why not post the code here so we can see what is happening? – John Palmer Sep 24 '15 at 10:58
  • As per my knowledge code is not issue for sure. Complicated code is only database connection and execute one procedure, nothing else. – Ravindra Sinare Sep 24 '15 at 11:56
  • It must be some part of your personal project since other people compile F# code quickly,and we can quickly check if it is the code is the problem – John Palmer Sep 24 '15 at 12:03
  • I have added code please check it. One file I have remove and one file contains only few type (definitions). – Ravindra Sinare Sep 25 '15 at 05:11

2 Answers2

5

Okay, seeing your actual code, I think the main problem is that the type provider connects to the database every time to retrieve the schema. The way to fix this is to cache the schema in a dbml file.

type dbSchema = SqlDataConnection<"connection string...",
                                  LocalSchemaFile = "myDb.dbml",
                                  ForceUpdate = false>

The first time, the TP will connect to the database as usual, but it will also write the schema to myDb.dbml. On subsequent compiles, it will load the schema from myDb.dbml instead of connecting to the database.

Of course, this caching means that changes to the database are not reflected in the types. So every time you need to reload the schema from the database, you can set ForceUpdate to true, do a compile (which will connect to the db), and set it back to false to use the updated myDb.dbml.

Edit: you can even commit the dbml file to your source repository if you want. This will have the additional benefit to allow collaborators who don't have access to a development version of the database to compile the solution anyway.

Tarmil
  • 11,177
  • 30
  • 35
  • I have inserted these lines of code ** type dbSchema = SqlDataConnection<"","EmpPersonal","D:\myDb.dbml",false>** Build/rebuild 4 times still takes almost 1 min to build.(little bit improve the time.) – Ravindra Sinare Sep 24 '15 at 12:33
  • I there any settings in project that causes this build time. – Ravindra Sinare Sep 24 '15 at 12:34
  • Can you make sure that you are not hitting db? Maybe just disconnect network cable? Did you check if all time is spent in fsc? Msbuild has options to profile builds, eg /v:diag – MichalMa Sep 25 '15 at 19:37
  • thanks! Local schema file and ForceUpdate= false reduced my compile time from 3 minutes to a few seconds! – FistOfFury Aug 17 '16 at 14:48
2

This answer about NGEN helped me once, but the build time of F# is still terrible compared to C#, just not minutes.

Community
  • 1
  • 1
V.B.
  • 6,236
  • 1
  • 33
  • 56
  • I have one another project of f#, It will not taking time as much this project is taking. I am using 4.0 framework and 3.0 f# compiler. – Ravindra Sinare Sep 24 '15 at 09:11
  • I have seen a blog post about how to explode a compiler with recursion, try catch and inline functions. Not sure that was about F# and do not remember link/details, but if your 5 files with 20 lines each are doing something crazy, maybe it should take that time. Or maybe your slow project is just hitting some hot path many times - just try NGEN, it *could* help, but there is no guarantee that it will. – V.B. Sep 24 '15 at 11:05
  • Also, your tag says that you are using VS2013, why not upgrading to VS2015 and F# 4.0? – V.B. Sep 24 '15 at 11:08
  • Yes V.B. that may solve my problem, But if we get proper reason then it will help lot. I have added code for same please go through it. – Ravindra Sinare Sep 24 '15 at 12:21