I’m converting some PureBasic projects to Xojo. In these projects I use dictionaries a lot. I’m experiencing some serious performance issues here.
I’ve made a test script to demonstrate this.
PureBasic:
EnableExplicit
NewMap test.s(1000000)
Define x.i
For x = 1 To 1000000
test("Key " + Str(x)) = "Some value " + Str(x)
Next x
Xojo:
Dim test As New Dictionary
For x As Integer = 1 To 1000000
test.Value("Key " + x.ToText) = "Some value " + x.ToText
Next x
In PureBasic total time is 1 second. In Xojo it’s more than 20 minutes (I stopped it at that time; didn’t waited longer). In the PureBasic example you see that I define a minimum slot space (I can add more without having to re-dimension it). That improves the speed a lot. Without that it took 3 minutes.
Can I do the same optimization “trick” in Xojo?
NB: The above posted code examples are just examples to demonstrate the speed difference. The’re not exact snippets from the actual project.
[quote=256540:@Marco Hof]Well, in case
"Key " +
and
"Some value " +
are always the same, leave them out.
That way, you can also put CustomerID in as integer without the rest.[/quote]
It’s an example …
In real projects that static text may be different depending on some decisions. Like record 1 = “Text 1” and record 2-5 = “Text 2”.
The example was meant to demonstrate an issues caused by, as we now now, string manipulations. In that context it doesn’t matter how the static text was chosen.
If I manually modify the BinCount, I can cut that down to a little over 4 seconds. If I use the new framework Dictionary, it goes to around 7 seconds. But still nothing like what you’re seeing.
You didn’t mention in your example code above that you were using the new framework Dictionary as shown in your test project, but my results are the same: 7 seconds.