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

Swift API fine tuning and initial documentation of reader API #76

Merged
merged 19 commits into from
Jan 11, 2017
Merged

Swift API fine tuning and initial documentation of reader API #76

merged 19 commits into from
Jan 11, 2017

Conversation

hassila
Copy link
Contributor

@hassila hassila commented Jan 10, 2017

Some start on polish for:
#55
#75

for your consideration - if you are ok with the direction, I will spend some more time on it.

@hassila hassila mentioned this pull request Jan 10, 2017
@mzaks
Copy link
Owner

mzaks commented Jan 10, 2017

Yes, I like where it is going!

@mzaks
Copy link
Owner

mzaks commented Jan 10, 2017

One thing. I would rather keep all benchmark code in https://github.com/mzaks/FlatBuffersSwiftPerformanceTest
This way it can be more experimental.
So it would be nice if you could delete: FlatBuffersPerformanceTestDesktop/bench.swift

Remove the obsolete bench.swift file.
@hassila
Copy link
Contributor Author

hassila commented Jan 10, 2017

Sorry, that should have been gone, should be fixed now.

@mzaks
Copy link
Owner

mzaks commented Jan 10, 2017

What do you think about dropping the get prefix. It is a question of taste I am not sure about it. I think get prefix is common in Java but not sure if I saw Swift API using get prefix much. E.g

try getScalar(at: offset)
vs.
try scalar(at: offset)

or

guard index < getVectorElementCount(vectorOffset: vectorOffset) else {
vs.
guard index < vectorCount(at: vectorOffset) else {

What do you think?

@hassila
Copy link
Contributor Author

hassila commented Jan 10, 2017

I think that would be good actually, I can continue polish in that direction?

…nes, rename source files accordingly. Start dropping get prefix.
@hassila
Copy link
Contributor Author

hassila commented Jan 10, 2017

Ok, will push through a few other changes, can wait with merge of the PR for a while.

@mzaks
Copy link
Owner

mzaks commented Jan 10, 2017

OK! Ping me when you think PR is ready to be merged.

@mzaks
Copy link
Owner

mzaks commented Jan 10, 2017

@hassila what do you think about renaming Scalar to FlatBuffersScalar I stumbled upon it because I am also porting FlexBuffer - a schema less binary encoding also done by Wouter von Oortmerssen inf the FlatBuffers project. There I also have a Scalar type. Normally I would say it should be solved by Modules, but in case of FlatBuffers Swift and whole module optimisation compiler flag, it might be better to have a good old prefix to distinguish the types. I am not sure.

@hassila
Copy link
Contributor Author

hassila commented Jan 10, 2017

Just a quick question - why do you want to keep both projects together and not separated?

@mzaks
Copy link
Owner

mzaks commented Jan 10, 2017

I actually want to keep them separated. But they might end up in the same project as dependencies. Scalar is just such a common name that it could collide and because whole module optimisation user might want to keep it as source and not as module dependency

@hassila
Copy link
Contributor Author

hassila commented Jan 10, 2017

Ok, I think it is ready for review and merge if ok - will take a stab at the builder separately. Should probably wait with codegen changes for a bit though as there may be more iterations...

@hassila
Copy link
Contributor Author

hassila commented Jan 10, 2017

"I actually want to keep them separated. But they might end up in the same project as dependencies. Scalar is just such a common name that it could collide and because whole module optimisation user might want to keep it as source and not as module dependency"

Ah, I see.

Perhaps something could be done with nested types, would need some digging...

Otherwise the short term fix with FlatBuffersScalar would be ok I think, to allow for easy benefit of WMO as you suggest.

@hassila
Copy link
Contributor Author

hassila commented Jan 11, 2017

I'll do an iteration on the builder too now as part of this PR, so please hold again. WIP.

@mzaks
Copy link
Owner

mzaks commented Jan 11, 2017

Sorry I didn't merge it yet. I first waiting for travis for a while and than I forgot 😳
I will wait now.

@hassila
Copy link
Contributor Author

hassila commented Jan 11, 2017

No problems, will ping again when next revision is done.

data -> makeData according to Swift API guidelines (gives a hint that it is an expensive operation, which is good).
@hassila
Copy link
Contributor Author

hassila commented Jan 11, 2017

Ok, I think it is ready for your review!

- parameters:
- value: The value to add to the buffer
*/
public func append<T : Scalar>(value : T){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically it is a prepend. The buffers are built from back to front. @hassila I leave it up to you, if you want to rename it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, but I would probably argue for that the directionality of the layout is a hidden implementation detail (and probably append would then be easier to read at the call site, as the generated code using the append wouldn't know how the buffer is actually updated?), so I would vote for keeping it as is.

We can probably consider additional documentation on the implementation details separately (which would not be a bad thing either :-) )

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or would you prefer insert?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm ... insert sound more neutral. I think I like it :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_data.storeBytes(of: value, toByteOffset: index + leftCursor, as: T.self)
}

public func openObject(numOfProperties : Int) throws {
/**
Start an object update sequence
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about update. I guess Start object construction sequence, is a bit more appropriate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@discardableResult
public func addPropertyOffsetToOpenObject(propertyIndex : Int, offset : Offset) throws -> Int{
public func append(propertyIndex : Int, offset : Offset) throws -> Int{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also here appendfeels wrong. maybe insert(offset:toStartedObjectAt:) is very long but describes the function in the best possible way I think.

Copy link
Contributor Author

@hassila hassila Jan 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to reverse the arguments?

Looking at usage, current proposal:

        try! fbb.startObject(numOfProperties: 3)
        try! fbb.append(propertyIndex: 0, value: true, defaultValue: false)
        try! fbb.append(propertyIndex: 1, offset: sOffset)
        let oOffset = try! fbb.endObject()
        try! fbb.finish(offset: oOffset, fileIdentifier: nil)

would become:

        try! fbb.startObject(numOfProperties: 3)
        try! fbb.insert(value: true, defaultValue: false, toStartedObjectAt: 0)
        try! fbb.insert(offset: sOffset, toStartedObjectAt: 1)
        let oOffset = try! fbb.endObject()
        try! fbb.finish(offset: oOffset, fileIdentifier: nil)

Perhaps:

        try! fbb.startObject(numOfProperties: 3)
        try! fbb.update(value: true, defaultValue: false, toStartedObjectAt: 0)
        try! fbb.update(offset: sOffset, toStartedObjectAt: 1)
        let oOffset = try! fbb.endObject()
        try! fbb.finish(offset: oOffset, fileIdentifier: nil)

?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update gives me a feeling that I can exchange values. IMHO insert is ok, also I find the API reads fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, updated in c306411.

@mzaks
Copy link
Owner

mzaks commented Jan 11, 2017

Great job!

@mzaks mzaks merged commit b63f120 into mzaks:master Jan 11, 2017
@hassila
Copy link
Contributor Author

hassila commented Jan 11, 2017

Thanks, I'm sure more can be done, but it is an initial attempt! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants