Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve rowWithRange SkipSearch performance #82

Merged
merged 3 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 5.1.1+e7cc638 (Released 2024-1-26)
* Additions:
* [[#e7cc638](https://github.com/CSBiology/FsSpreadsheet/commit/e7cc638b170c570005b6cd8378d1e0ac31075be7)] improve rowWithRange SkipSearch performance

### 5.1.0+4732d22 (Released 2024-1-24)
* Additions:
* Increase Parser speed
Expand Down
2 changes: 1 addition & 1 deletion build/ReleaseTasks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ let publishNPM = BuildTask.create "PublishNPM" [clean; build; runTests; packJS]
let msg = sprintf "[NPM] release package with version %s?" stableVersionTag
if promptYesNo msg then
let apikey = Environment.environVarOrNone "NPM_KEY"
let otp = if apikey.IsSome then $" --otp + {apikey.Value}" else ""
let otp = if apikey.IsSome then $" --otp {apikey.Value}" else ""
run npm $"publish --access public{otp}" ProjectInfo.npmPkgDir
else failwith "aborted"
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fslab/fsspreadsheet",
"version": "5.1.0",
"version": "5.1.1",
"description": "Minimal spreadsheet creation and manipulation using exceljs io.",
"type": "module",
"main": "Xlsx.js",
Expand Down
10 changes: 8 additions & 2 deletions src/FsSpreadsheet/FsWorksheet.fs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,13 @@
/// <summary>
/// Returns the FsRow at the given index. If it does not exist, it is created and appended first.
/// </summary>
member self.Row(rowIndex) =
member self.Row(rowIndex, ?SkipSearch) =
let skipSearch = defaultArg SkipSearch false
if skipSearch then
let row = FsRow.createAt(rowIndex,self.CellCollection)
_rows.Add row
row
else
match _rows |> Seq.tryFind (fun row -> row.Index = rowIndex) with
| Some row ->
row
Expand All @@ -141,7 +147,7 @@
_rows.Add row
row

/// <summary>

Check warning on line 150 in src/FsSpreadsheet/FsWorksheet.fs

View workflow job for this annotation

GitHub Actions / build-and-test-windows

This XML comment is incomplete: no documentation for parameter 'rangeAddress'

Check warning on line 150 in src/FsSpreadsheet/FsWorksheet.fs

View workflow job for this annotation

GitHub Actions / build-and-test-linux

This XML comment is incomplete: no documentation for parameter 'rangeAddress'
/// Returns the FsRow at the given FsRangeAddress. If it does not exist, it is created and appended first.
/// </summary>
/// <param name="SkipSearch">If true, the FsRow is created and appended without checking if it already exists.</param>
Expand All @@ -150,7 +156,7 @@
if rangeAddress.FirstAddress.RowNumber <> rangeAddress.LastAddress.RowNumber then
failwithf "Row may not have a range address spanning over different row indices"
if skipSearch then
let row = FsRow.createAt(rangeAddress.FirstAddress.RowNumber,self.CellCollection)
let row = FsRow (rangeAddress, self.CellCollection)
row.RangeAddress <- rangeAddress
_rows.Add row
row
Expand Down
30 changes: 28 additions & 2 deletions tests/FsSpreadsheet.Tests/FsRowTests.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module FsRow


open TestingUtils
#if FABLE_COMPILER
open Fable.Mocha
#else
Expand All @@ -17,7 +17,27 @@ let getDummyWorkSheet() =
worksheet.RescanRows()
worksheet

let main =

let performace =
testList "performance" [
testCase "FrowFromRange-SkipSearch" (fun () ->
let rowCount= 100000
let ws = FsWorksheet.init("MyWorksheet")
let timer = Stopwatch()
timer.Start()
for i = 1 to rowCount do
let address = FsRangeAddress(FsAddress(i,1), FsAddress(i,1))
ws.RowWithRange(address,true) |> ignore
timer.Stop()
let runtime = timer.Elapsed.Milliseconds
let expected = 50 // this is too high and should be reduced

Expect.equal ws.Rows.Count rowCount "Row count"
Expect.isTrue (runtime <= expected) $"Expected conversion to be finished in under {expected}, but it took {runtime}"
)
]

let rowOperations =
testList "rowOperations" [
testList "Prerequisites" [
let dummyWorkSheet = getDummyWorkSheet()
Expand Down Expand Up @@ -117,3 +137,9 @@ let main =
Expect.equal maxColIndex 1 "Incorrect index"
]
]

let main =
testList "FsRow" [
rowOperations
performace
]
1 change: 1 addition & 0 deletions tests/FsSpreadsheet.Tests/FsSpreadsheet.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

<ItemGroup>
<ProjectReference Include="..\..\src\FsSpreadsheet\FsSpreadsheet.fsproj" />
<ProjectReference Include="..\TestUtils\TestUtils.fsproj" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading