Swift App Takes ~6 Minutes To Build - ios

I have a Swift app with an array of about ~100k strings. The array looks something like this:
let strings: [String] = [
"a",
"as",
// 99,998 elements later...
"zebra"
]
It takes nearly 6 minutes to build and run the app in the iOS Simulator. I've isolated the slow build time to the inclusion of this array in the project. Once built, subsequent launches are very fast (until I have to build again). What can I do to speed up the build process?

Per the comments above, the best solution for me was to use a text file. A database would have worked too, though it would've added unnecessarily complexity in this case. The text file looks something like this:
a
as
...
zebra
The file is read using the StreamReader gist from this SO post. The code for doing so looks like this:
if let aStreamReader = StreamReader(path: "/path/to/file") {
for word in aStreamReader {
// This is where I'm testing the following conditions:
// 1) Does the word have a specific number of characters (e.g. 4 or 7)?
// 2) Do all the characters in the word exist in a stored string?
// e.g "lifeline", where "file" would match, but "lifelines" wouldn't.
// This code is only here for context.
if contains(characterCountsToMatch, countElements(word)) {
if stringToMatch.containsCharsInString(word) {
matchingWords.append(word)
}
}
}
}
The resulting matchingWords array contains only the necessary elements–about 600 in my case (not ~100k elements!). The application now compiles with no delay. Reading from the file and appending matches to the matchingWords array takes about 5 seconds, which is acceptable for my needs, but could be further optimized if needed.

Related

Differentiating Mode 2 Form 1 from Mode 2 Form 2 on XA CD-ROMs?

I'm developing a library for reading CD-ROMs and the ISO9660 file system.
Long story short, pretty much everything is working except for one thing I'm having a hard time figuring out how it's done:
Where does XA standard defines differentiation among Mode 2 Form 1 from Mode 2 Form 2?
Currently, I am using the following pseudo-code to differentiate between both forms; albeit it's a naive heuristic, it does work but well, it's far from ideal:
var buffer = ... // this is a raw sector of 2352 bytes
var m2F1 = ISector.Cast<SectorMode2Form1>(buffer);
var edc1 = EdcHelper.ComputeBlock(0, buffer, 16, 2056);
var edc2 = BitConverter.ToUInt32(m2F1.Edc, 0);
var isM2F1 = edc1 == edc2;
if (isM2F1) return CdRomSectorMode.Mode2Form1;
// NOTE we cannot reliably check EDC of M2F2 since it's optional
var isForm2 =
m2F1.SubHeaderCopy1.SubMode.HasFlag(SectorMode2Form1SubHeaderSubMode.Form2) &&
m2F1.SubHeaderCopy2.SubMode.HasFlag(SectorMode2Form1SubHeaderSubMode.Form2);
if (isForm2) return CdRomSectorMode.Mode2Form2;
return CdRomSectorMode.Mode2Formless;
If you look at some software like IsoBuster, it appears to be a track-level property, however, I'm failing to understand where the value would be read from within the track.
I'm actually doing something similar in typescript for my ps1 mod tools. It seems like you actually probably have it correct here, since I'm going to assume your HasFlag check is checking position bit position 6 of the subheader. If that flag is set, you are in form 2.
So what you probably want something like:
const sectorBytes = new Uint8Arrray(buffer);
if (sectorBytes[0x012] & 0x20) === 0x20) {
return CdRomSectorMode.Mode2Form2;
} else {
return CdRomSectorMode.Mode2Form1;
}
You could of course use the flag code you already have, but that would require you to use one of the types first to get that. This just keeps it generic bytes and checks the flag, then returns the relevant mode.

How to correctly return a list of dictionaries in Zapier Code (Python)?

The Zapier code documentation says that the output of a code zap can be either a dictionary or a list of dictionaries (See "Data Variable" section: https://zapier.com/help/code-python/).
When doing this,
output = [{'Booking':'Shirt'},{'Booking':'Jeans'}]
the output of the code returns only the first dictionary, however:
runtime_meta__duration_ms: 2
runtime_meta__memory_used_mb: 22
id: [redacted]
Booking: Shirt
Fields with no value:
runtime_meta__logs
What am I doing wrong here? Thanks a lot!
David from the Zapier platform team here. Code steps returning an array is a mostly undocumented (because there's no UI support and it's confusing, as you can tell) feature.
When testing, it'll only show the first item in the array. When it runs for real, all steps after the code step will run for each item in the array. The task history will reflect this
So set up the zap and turn on and it'll work like you expect.
Sorry for the confusion and let me know if you have any other questions!
For anyone still looking for an answer to this questions, below is what find out returning list in Zapier.
# first import and convert your input value to an array.
# special note any line items imported into a python variable are converted to list format.
my_items = input_data['my_CSV_string']
my_list_of_items = my_items.split(",")
# Create a new list array
my_new_list = []
length = len(my_list_of_items)
#Do all your computations
for i in range(length):
my_new_list.append(float(my_list_of_items[i])*1.5)
# After completing any tasks you can return the list as follows,
# If you are using line items keep the list in its original format
return {
'my_processed_values': my_new_list,
'original_values': my_list_of_items
}
# If you want to return it as a CSV "basically making the array flat"
my_old_CSV_list= ','.join(map(str, my_list_of_items))
my_new_CSV_list= ','.join(map(str, my_new_list))
return {
'my_processed_cvs_values': my_new_CSV_list,
'original_values': my_list_of_items
}
Hope this helps. I am not a Python expert but in theory the more lists used the longer the zap will take to process. Try to keep your python processing time to the lowest.
Best,

nsIProperty.get to something other than nsIFile - fastest way to get special path strings

Is it possible to use nsIProperty.get to get special path into something other than a nsIFile? I tried nsISupportsString but it doesnt work. There's gotta be something other than nsIFile it should get on right, why else would they make it an argument?
Im looking for the fastest way to get special path strings, because this stuff is happening on a 200ms animation of a panel element these times are critical to me.
Heres some speed analysis:
// FileUtils.jsm :: getFile
// average time: 3.85ms
console.time('path'); var path = FileUtils.getFile('DefProfRt', []).path; console.timeEnd('path'); console.log(path);
// nsIDirectoryService :: nsIProperties :: get - nsIFile
// average time: 0.07ms
console.time('path'); var path = Cc["#mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties).get('DefProfRt', Ci.nsIFile).path; console.timeEnd('path'); console.log(path);
// OS.Constants.Path
// average time: 0.12ms
console.time('path'); var path = OS.Constants.Path.profileDir; console.timeEnd('path'); console.log(path);
I don't get why OS.Constants.Path takes longer than nsIProperties.get as OS.Constants.Path is hardcoded I thought.
All three ways end to the same native code, but the nsIDirectoryService approach involves less javascript than the other two.
You can't get any faster, nsIFile is not a bottleneck here since no filesystem operation occurs. Merely string concatenation.
If 0.07ms is not good enough, you 're doing something wrong.

readByteSync - is this behavior correct?

stdin.readByteSync has recently been added to Dart.
Using stdin.readByteSync for data entry, I am attempting to allow a default value and if an entry is made by the operator, to clear the default value. If no entry is made and just enter is pressed, then the default is used.
What appears to be happening however is that no terminal output is sent to the terminal until a newline character is entered. Therefore when I do a print() or a stdout.write(), it is delayed until newline is entered.
Therefore, when operator enters first character to override default, the default is not cleared. IE. The default is "abc", data entered is "xx", however "xxc" is showing on screen after entry of "xx". The "problem" appears to be that no "writes" to the terminal are sent until newline is entered.
While I can find an alternative way of doing this, I would like to know if this is the way readByteSync should or must work. If so, I’ll find an alternative way of doing what I want.
// Example program //
import 'dart:io';
void main () {
int iInput;
List<int> lCharCodes = [];
print(""); print("");
String sDefault = "abc";
stdout.write ("Enter data : $sDefault\b\b\b");
while (iInput != 10) { // wait for newline
iInput = stdin.readByteSync();
if (iInput == 8 && lCharCodes.length > 0) { // bs
lCharCodes.removeLast();
} else if (iInput > 31) { // ascii printable char
lCharCodes.add(iInput);
if (lCharCodes.length == 1)
stdout.write (" \b\b\b\b chars cleared"); // clear line
print ("\nlCharCodes length = ${lCharCodes.length}");
}
}
print ("\nData entered = ${new String.fromCharCodes(lCharCodes).trim()}");
}
Results on Command screen are :
c:\Users\Brian\dart-dev1\test\bin>dart testsync001.dart
Enter data : xxc
chars cleared
lCharCodes length = 1
lCharCodes length = 2
Data entered = xx
c:\Users\Brian\dart-dev1\test\bin>
I recently added stdin.readByteSync and readLineSync, to easier create small scrips reading the stdin. However, two things are still missing, for this to be feature-complete.
1) Line mode vs Raw mode. This is basically what you are asking for, a way to get a char as soon as it's printed.
2) Echo on/off. This mode is useful for e.g. typing in passwords, so you can disable the default echo of the characters.
I hope to be able to implement and land these features rather soon.
You can star this bug to track the development of it!
This is common behavior for consoles. Try to flush the output with stdout.flush().
Edit: my mistake. I looked at a very old revision (dartlang-test). The current API does not provide any means to flush stdout. Feel free to file a bug.

How to cache many images(in loop) properly using forge.file.cacheURL?

I have a list of products that I download as json file from server. Each item contains a link to the image stored on server.
Now I want to be able to see the products when offline, so I store downloaded json file into forge.prefs http://docs.trigger.io/en/v1.3/modules/prefs.html and pull it out to display items on screen. It works nice but I also need to store images localy to be displayed correctly.
To achive this, I'm trying to use forge.file.cacheURL http://docs.trigger.io/en/v1.3/features/cache.html but can't handle the correct order of operations. To cache images I run the json file and for each line I call forge.file.cacheURL and store the url back to JSON item. But here is the problem as forge.file.cacheURL runs asynchronously so my loop running over the items and gathering the local images finishes and my code continues to display images(view items) but meantime the forge.file.cacheURL still gathers and caches the images because its asynchronous operation. I need somehow to detect that last item is being cached and then refresh the view on screen to use correct image urls ... or something else that will lead to what I need.
Hopefully you understand the concept. How should I handle this properly ?
Since v1.4.26 you've been able to permanently store images (see http://docs.trigger.io/en/v1.4/release-notes.html#v1-4-26), rather than just cache them. Depending on your needs, that might be a better option than forge.file.cacheURL and forge.file.isFile.
I don't follow exactly the situation you describe, but something like this will let you wait for several asynchronous things to finish before doing something:
// e.g.
var jsonCache = {
one: "http://example.com/one.jpg",
two: "http://example.com/two.jpg",
three: "http://example.com/three.jpg"
};
var cacheCount = 0;
for (var name in jsonCache) {
if (jsonCache.hasOwnProperty(name)) {
var imageURL = jsonCache[name];
cacheCount += 1;
forge.file.cacheURL(imageURL, function (file) {
forge.prefs.set(name, file, function () {
cacheCount -= 1; // race condition, but should be fine (!)
if (cacheCount <= 0) {
alert('all cached');
}
});
});
}
}

Resources